1 package test.net.sourceforge.pmd.rules.design;
2
3 import net.sourceforge.pmd.PMD;
4 import net.sourceforge.pmd.rules.design.ExceptionAsFlowControlRule;
5 import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
6 import test.net.sourceforge.pmd.testframework.TestDescriptor;
7
8 public class ExceptionAsFlowControlRuleTest extends SimpleAggregatorTst {
9
10 public void testAll() {
11 runTests(new TestDescriptor[] {
12 new TestDescriptor(TEST1, "failure case", 1, new ExceptionAsFlowControlRule()),
13 new TestDescriptor(TEST2, "normal throw catch", 0, new ExceptionAsFlowControlRule())
14 });
15 }
16
17 private static final String TEST1 =
18 "public class Foo {" + PMD.EOL +
19 " void bar() {" + PMD.EOL +
20 " try {" + PMD.EOL +
21 " try {" + PMD.EOL +
22 " } catch (Exception e) {" + PMD.EOL +
23 " throw new WrapperException(e);" + PMD.EOL +
24 " // this is essentially a GOTO to the WrapperException catch block" + PMD.EOL +
25 " }" + PMD.EOL +
26 " } catch (WrapperException e) {" + PMD.EOL +
27 " // do some more stuff " + PMD.EOL +
28 " }" + PMD.EOL +
29 " }" + PMD.EOL +
30 "}";
31
32 private static final String TEST2 =
33 "public class Foo {" + PMD.EOL +
34 " void bar() {" + PMD.EOL +
35 " try {} catch (Exception e) {}" + PMD.EOL +
36 " }" + PMD.EOL +
37 "}";
38 }