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