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.apache.tools.ant.BuildFileTest;
7   import org.junit.Test;
8   
9   public class PMDTaskTest extends BuildFileTest {
10  
11      @Override
12      public void setUp() {
13          // initialize Ant    	
14          configureProject("target/test-classes/net/sourceforge/pmd/ant/xml/pmdtasktest.xml");
15          if (!project.getBaseDir().toString().endsWith("pmd/ant/xml")) {
16              // when running from maven, the path needs to be adapted...
17              // FIXME: this is more a workaround than a good solution...
18              project.setBasedir(project.getBaseDir().toString()
19          	    + "/target/test-classes/net/sourceforge/pmd/ant/xml");
20          }
21      }
22  
23      @Test
24      public void testNoFormattersValidation() {
25          executeTarget("testNoFormattersValidation");
26          assertOutputContaining("Fields should be declared at the top of the class");
27      }
28  
29      @Test
30      public void testFormatterWithNoToFileAttribute() {
31          expectBuildExceptionContaining("testFormatterWithNoToFileAttribute", "Valid Error Message", "toFile or toConsole needs to be specified in Formatter");
32      }
33  
34      @Test
35      public void testNoRuleSets() {
36          expectBuildExceptionContaining("testNoRuleSets", "Valid Error Message", "No rulesets specified");
37      }
38  
39      @Test
40      public void testNestedRuleset() {
41          executeTarget("testNestedRuleset");
42          assertOutputContaining("Avoid really long methods");
43          assertOutputContaining("Deeply nested if");
44      }
45  
46      @Test
47      public void testFormatterWithProperties() {
48          executeTarget("testFormatterWithProperties");
49          assertOutputContaining("Avoid really long methods");
50          assertOutputContaining("Deeply nested if");
51          assertOutputContaining("link_prefix");
52          assertOutputContaining("line_prefix");
53      }
54  
55      @Test
56      public void testAbstractNames() {
57          executeTarget("testAbstractNames");
58          assertOutputContaining("Avoid really long methods");
59          assertOutputContaining("Deeply nested if");
60      }
61  
62      @Test
63      public void testAbstractNamesInNestedRuleset() {
64          executeTarget("testAbstractNamesInNestedRuleset");
65          assertOutputContaining("Avoid really long methods");
66          assertOutputContaining("Deeply nested if");
67      }
68  
69      @Test
70      public void testCommaInRulesetfiles() {
71          executeTarget("testCommaInRulesetfiles");
72          assertOutputContaining("Avoid really long methods");
73          assertOutputContaining("Deeply nested if");
74      }
75  
76      @Test
77      public void testRelativeRulesets() {
78          executeTarget("testRelativeRulesets");
79          assertOutputContaining("Avoid really long methods");
80          assertOutputContaining("Deeply nested if");
81      }
82  
83      @Test
84      public void testRelativeRulesetsInRulesetfiles() {
85          executeTarget("testRelativeRulesetsInRulesetfiles");
86          assertOutputContaining("Avoid really long methods");
87          assertOutputContaining("Deeply nested if");
88      }
89  
90      @Test
91      public void testBasic() {
92          executeTarget("testBasic");
93      }
94  
95      @Test
96      public void testInvalidLanguageVersion() {
97          expectBuildExceptionContaining("testInvalidLanguageVersion", "Fail requested.", "The <version> element, if used, must be one of 'java 1.3', 'java 1.4', 'java 1.5', 'java 1.6', 'java 1.7'.");
98      }
99      
100     @Test
101     public void testExplicitRuleInRuleSet() {
102         executeTarget("testExplicitRuleInRuleSet");
103         assertOutputContaining("Avoid really long methods");
104     }
105 
106     public static junit.framework.Test suite() {
107         return new junit.framework.JUnit4TestAdapter(PMDTaskTest.class);
108     }
109 }