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.AvoidDeeplyNestedIfStmtsRule;
6
7 public class AvoidDeeplyNestedIfStmtsRuleTest extends RuleTst {
8
9 public static final String TEST1 =
10 "public class AvoidDeeplyNestedIfStmtsRule1 {" + PMD.EOL +
11 " public void bar() { " + PMD.EOL +
12 " int x=2; " + PMD.EOL +
13 " int y=3; " + PMD.EOL +
14 " int z=4; " + PMD.EOL +
15 " if (x>y) { " + PMD.EOL +
16 " if (y>z) { " + PMD.EOL +
17 " if (z==x) { " + PMD.EOL +
18 " // this is officially out of control now " + PMD.EOL +
19 " } " + PMD.EOL +
20 " } " + PMD.EOL +
21 " }" + PMD.EOL +
22 " }" + PMD.EOL +
23 "}";
24
25 public static final String TEST2 =
26 "public class AvoidDeeplyNestedIfStmtsRule2 {" + PMD.EOL +
27 " public void bar() { " + PMD.EOL +
28 " if (true) {" + PMD.EOL +
29 " } else if (true) {" + PMD.EOL +
30 " } else if (true) {" + PMD.EOL +
31 " } else {" + PMD.EOL +
32 " // this ain't good code, but it shouldn't trigger this rule" + PMD.EOL +
33 " }" + PMD.EOL +
34 " }" + PMD.EOL +
35 "}";
36
37 private Rule rule;
38
39 public void setUp() {
40 rule = new AvoidDeeplyNestedIfStmtsRule();
41 rule.addProperty("problemDepth", "3");
42 }
43
44 public void test1() throws Throwable {
45 runTestFromString(TEST1, 1, rule);
46 }
47
48 public void test2() throws Throwable {
49 runTestFromString(TEST2, 0, rule);
50 }
51 }
This page was automatically generated by Maven