View Javadoc

1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.ant;
5   
6   import org.junit.Test;
7   
8   public class PMDTaskTest extends AbstractAntTestHelper {
9   
10  	public PMDTaskTest() {
11  		super.antTestScriptFilename = "pmdtasktest.xml";
12  	}
13  
14      @Test
15      public void testNoFormattersValidation() {
16          executeTarget("testNoFormattersValidation");
17          assertOutputContaining("Fields should be declared at the top of the class");
18      }
19  
20      @Test
21      public void testFormatterWithNoToFileAttribute() {
22          expectBuildExceptionContaining("testFormatterWithNoToFileAttribute", "Valid Error Message", "toFile or toConsole needs to be specified in Formatter");
23      }
24  
25      @Test
26      public void testNoRuleSets() {
27          expectBuildExceptionContaining("testNoRuleSets", "Valid Error Message", "No rulesets specified");
28      }
29  
30      @Test
31      public void testNestedRuleset() {
32          executeTarget("testNestedRuleset");
33          assertOutputContaining("Avoid really long methods");
34          assertOutputContaining("Fields should be declared at the");
35      }
36  
37      @Test
38      public void testFormatterWithProperties() {
39          executeTarget("testFormatterWithProperties");
40          assertOutputContaining("Avoid really long methods");
41          assertOutputContaining("Fields should be declared at the");
42          assertOutputContaining("link_prefix");
43          assertOutputContaining("line_prefix");
44      }
45  
46      @Test
47      public void testAbstractNames() {
48          executeTarget("testAbstractNames");
49          assertOutputContaining("Avoid really long methods");
50          assertOutputContaining("Fields should be declared at the");
51      }
52  
53      @Test
54      public void testAbstractNamesInNestedRuleset() {
55          executeTarget("testAbstractNamesInNestedRuleset");
56          assertOutputContaining("Avoid really long methods");
57          assertOutputContaining("Fields should be declared at the");
58      }
59  
60      @Test
61      public void testCommaInRulesetfiles() {
62          executeTarget("testCommaInRulesetfiles");
63          assertOutputContaining("Avoid really long methods");
64          assertOutputContaining("Fields should be declared at the");
65      }
66  
67      @Test
68      public void testRelativeRulesets() {
69          executeTarget("testRelativeRulesets");
70          assertOutputContaining("Avoid really long methods");
71          assertOutputContaining("Fields should be declared at the");
72      }
73  
74      @Test
75      public void testRelativeRulesetsInRulesetfiles() {
76          executeTarget("testRelativeRulesetsInRulesetfiles");
77          assertOutputContaining("Avoid really long methods");
78          assertOutputContaining("Fields should be declared at");
79      }
80  
81      @Test
82      public void testBasic() {
83          executeTarget("testBasic");
84      }
85  
86      @Test
87      public void testInvalidLanguageVersion() {
88          expectBuildExceptionContaining("testInvalidLanguageVersion", "Fail requested.", "The following language is not supported:<language name=\"java\" version=\"42\" />.");
89      }
90  
91      @Test
92      public void testExplicitRuleInRuleSet() {
93          executeTarget("testExplicitRuleInRuleSet");
94          assertOutputContaining("Avoid really long methods");
95      }
96      
97      @Test
98      public void testEcmascript() {
99          executeTarget("testEcmascript");
100         assertOutputContaining("A 'return', 'break', 'continue', or 'throw' statement should be the last in a block.");
101         assertOutputContaining("Avoid using global variables");
102         assertOutputContaining("Use ===/!== to compare with true/false or Numbers");
103     }
104 
105     @Test
106     public void testXML() {
107         executeTarget("testXML");
108         assertOutputContaining("Potentialy mistyped CDATA section with extra [ at beginning or ] at the end.");
109     }
110 
111     @Test
112     public void testClasspath() {
113         executeTarget("testClasspath");
114     }
115 
116     public static junit.framework.Test suite() {
117         return new junit.framework.JUnit4TestAdapter(PMDTaskTest.class);
118     }
119 }