1 package test.net.sourceforge.pmd.rules;
2
3 import net.sourceforge.pmd.PMD;
4 import net.sourceforge.pmd.Rule;
5 import net.sourceforge.pmd.rules.XPathRule;
6
7 public class ForLoopShouldBeWhileLoopRuleTest extends SimpleAggregatorTst {
8
9 private Rule rule;
10
11 public void setUp() {
12 rule = new XPathRule();
13 rule.addProperty(
14 "xpath",
15 "//ForStatement[count(*) > 1][not(ForInit)][not(ForUpdate)]");
16 }
17
18 public void testAll() {
19 runTests(new TestDescriptor[] {
20 new TestDescriptor(TEST1, "simple failure case", 1, rule),
21 new TestDescriptor(TEST2, "ok", 0, rule),
22 new TestDescriptor(TEST3, "for loop like this: for (;;) {} ", 0, rule),
23 });
24 }
25
26 private static final String TEST1 =
27 "public class ForLoopShouldBeWhileLoop1 {" + PMD.EOL +
28 " public void foo() {" + PMD.EOL +
29 " int x = 2;" + PMD.EOL +
30 " for (;x<5;) { " + PMD.EOL +
31 " x++;" + PMD.EOL +
32 " }" + PMD.EOL +
33 " }" + PMD.EOL +
34 "}";
35
36 private static final String TEST2 =
37 "public class ForLoopShouldBeWhileLoop2 {" + PMD.EOL +
38 " public void foo() {" + PMD.EOL +
39 " for (int x=2;x<5;) { " + PMD.EOL +
40 " x++;" + PMD.EOL +
41 " }" + PMD.EOL +
42 " }" + PMD.EOL +
43 "}";
44
45 private static final String TEST3 =
46 "public class ForLoopShouldBeWhileLoop3 {" + PMD.EOL +
47 " public void foo() {" + PMD.EOL +
48 " for (;;) {}" + PMD.EOL +
49 " }" + PMD.EOL +
50 "}";
51
52 }
This page was automatically generated by Maven