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.XPathRule; 9 import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; 10 import test.net.sourceforge.pmd.testframework.TestDescriptor; 11 12 public class IfElseStmtsMustUseBracesRuleTest extends SimpleAggregatorTst { 13 14 private Rule rule; 15 16 public void setUp() { 17 rule = new XPathRule(); 18 rule.addProperty("xpath", "//IfStatement[count(*) > 2][not(Statement/Block)]"); 19 } 20 21 public void testAll() { 22 runTests(new TestDescriptor[] { 23 new TestDescriptor(TEST1, "simple failure case", 1, rule), 24 new TestDescriptor(TEST2, "ok", 0, rule), 25 }); 26 } 27 28 private static final String TEST1 = 29 "public class IfElseStmtsNeedBraces1 {" + PMD.EOL + 30 " public void foo() { " + PMD.EOL + 31 " int x =0;" + PMD.EOL + 32 " if (true == true) " + PMD.EOL + 33 " x=2;" + PMD.EOL + 34 " else " + PMD.EOL + 35 " x=4;" + PMD.EOL + 36 " }" + PMD.EOL + 37 "}"; 38 39 private static final String TEST2 = 40 "public class IfElseStmtsNeedBraces2 {" + PMD.EOL + 41 " public void foo() { " + PMD.EOL + 42 " int x =0;" + PMD.EOL + 43 " if (true == true) {" + PMD.EOL + 44 " x=2;" + PMD.EOL + 45 " } else {" + PMD.EOL + 46 " x=4;" + PMD.EOL + 47 " }" + PMD.EOL + 48 " }" + PMD.EOL + 49 "}"; 50 51 52 53 }

This page was automatically generated by Maven