View Javadoc
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 EmptyTryBlockRuleTest extends SimpleAggregatorTst { 8 9 private Rule rule; 10 11 public void setUp() { 12 rule = new XPathRule(); 13 rule.addProperty("xpath", "//TryStatement/Block[1][count(*) = 0]"); 14 } 15 16 public void testAll() { 17 runTests(new TestDescriptor[] { 18 new TestDescriptor(TEST1, "bad", 1, rule), 19 new TestDescriptor(TEST2, "bad", 1, rule), 20 new TestDescriptor(TEST3, "ok", 0, rule) 21 }); 22 } 23 24 private static final String TEST1 = 25 "public class EmptyTryBlock1 {" + PMD.EOL + 26 " public void foo() {" + PMD.EOL + 27 " try {" + PMD.EOL + 28 " } catch (Exception e) {" + PMD.EOL + 29 " e.printStackTrace();" + PMD.EOL + 30 " }" + PMD.EOL + 31 " }" + PMD.EOL + 32 "}"; 33 34 private static final String TEST2 = 35 "public class EmptyTryBlock2 {" + PMD.EOL + 36 " public void foo() {" + PMD.EOL + 37 " try {" + PMD.EOL + 38 " } finally {" + PMD.EOL + 39 " int x = 5;" + PMD.EOL + 40 " }" + PMD.EOL + 41 " }" + PMD.EOL + 42 "}"; 43 44 private static final String TEST3 = 45 "public class EmptyTryBlock3 {" + PMD.EOL + 46 " public void foo() {" + PMD.EOL + 47 " try {" + PMD.EOL + 48 " int f =2;" + PMD.EOL + 49 " } finally {" + PMD.EOL + 50 " int x = 5;" + PMD.EOL + 51 " }" + PMD.EOL + 52 " }" + PMD.EOL + 53 "}"; 54 55 }

This page was automatically generated by Maven