1
2
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
14 configureProject("target/test-classes/net/sourceforge/pmd/ant/xml/pmdtasktest.xml");
15 if (!project.getBaseDir().toString().endsWith("pmd/ant/xml")) {
16
17
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("Fields should be declared at the");
44 }
45
46 @Test
47 public void testFormatterWithProperties() {
48 executeTarget("testFormatterWithProperties");
49 assertOutputContaining("Avoid really long methods");
50 assertOutputContaining("Fields should be declared at the");
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("Fields should be declared at the");
60 }
61
62 @Test
63 public void testAbstractNamesInNestedRuleset() {
64 executeTarget("testAbstractNamesInNestedRuleset");
65 assertOutputContaining("Avoid really long methods");
66 assertOutputContaining("Fields should be declared at the");
67 }
68
69 @Test
70 public void testCommaInRulesetfiles() {
71 executeTarget("testCommaInRulesetfiles");
72 assertOutputContaining("Avoid really long methods");
73 assertOutputContaining("Fields should be declared at the");
74 }
75
76 @Test
77 public void testRelativeRulesets() {
78 executeTarget("testRelativeRulesets");
79 assertOutputContaining("Avoid really long methods");
80 assertOutputContaining("Fields should be declared at the");
81 }
82
83 @Test
84 public void testRelativeRulesetsInRulesetfiles() {
85 executeTarget("testRelativeRulesetsInRulesetfiles");
86 assertOutputContaining("Avoid really long methods");
87 assertOutputContaining("Fields should be declared at");
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 following language is not supported:<language name=\"java\" version=\"42\" />.");
98 }
99
100 @Test
101 public void testExplicitRuleInRuleSet() {
102 executeTarget("testExplicitRuleInRuleSet");
103 assertOutputContaining("Avoid really long methods");
104 }
105
106 @Test
107 public void testEcmascript() {
108 executeTarget("testEcmascript");
109 assertOutputContaining("A 'return', 'break', 'continue', or 'throw' statement should be the last in a block.");
110 assertOutputContaining("Avoid using global variables");
111 assertOutputContaining("Use ===/!== to compare with true/false or Numbers");
112 }
113
114 @Test
115 public void testXML() {
116 executeTarget("testXML");
117 assertOutputContaining("Potentialy mistyped CDATA section with extra [ at beginning or ] at the end.");
118 }
119
120 @Test
121 public void testClasspath() {
122 executeTarget("testClasspath");
123 }
124
125 public static junit.framework.Test suite() {
126 return new junit.framework.JUnit4TestAdapter(PMDTaskTest.class);
127 }
128 }