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 EmptyFinallyBlockRuleTest extends SimpleAggregatorTst { 8 9 private Rule rule; 10 11 public void setUp() { 12 rule = new XPathRule(); 13 rule.addProperty( 14 "xpath", 15 "//TryStatement[@Finally='true']/Block[position() = last()][count(*) = 0]"); 16 } 17 18 public void testAll() { 19 runTests(new TestDescriptor[] { 20 new TestDescriptor(TEST1, "", 1, rule), 21 new TestDescriptor(TEST2, "", 1, rule), 22 new TestDescriptor(TEST3, "", 0, rule), 23 new TestDescriptor(TEST4, "multiple catch blocks with finally", 1, rule), 24 }); 25 } 26 27 private static final String TEST1 = 28 "public class EmptyFinallyBlock1 {" + PMD.EOL + 29 " public void foo() {" + PMD.EOL + 30 " try {" + PMD.EOL + 31 " } catch (Exception e) {} finally {}" + PMD.EOL + 32 " }" + PMD.EOL + 33 "}"; 34 35 private static final String TEST2 = 36 "public class EmptyFinallyBlock2 {" + PMD.EOL + 37 " public void foo() {" + PMD.EOL + 38 " try {" + PMD.EOL + 39 " } finally {}" + PMD.EOL + 40 " }" + PMD.EOL + 41 "}"; 42 43 private static final String TEST3 = 44 "public class EmptyFinallyBlock3 {" + PMD.EOL + 45 " public void foo() {" + PMD.EOL + 46 " try {" + PMD.EOL + 47 " } finally {int x =2;}" + PMD.EOL + 48 " }" + PMD.EOL + 49 "}"; 50 51 private static final String TEST4 = 52 "public class EmptyFinallyBlock4 {" + PMD.EOL + 53 " public void foo() {" + PMD.EOL + 54 " try {" + PMD.EOL + 55 " } catch (IOException e ){" + PMD.EOL + 56 " } catch (Exception e ) {" + PMD.EOL + 57 " } catch (Throwable t ) {" + PMD.EOL + 58 " } finally{" + PMD.EOL + 59 " }" + PMD.EOL + 60 " }" + PMD.EOL + 61 "}"; 62 63 }

This page was automatically generated by Maven