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

This page was automatically generated by Maven