1   /***
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3   */
4   package test.net.sourceforge.pmd.rules.strictexception;
5   
6   import net.sourceforge.pmd.PMD;
7   import net.sourceforge.pmd.rules.strictexception.AvoidCatchingThrowable;
8   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
9   import test.net.sourceforge.pmd.testframework.TestDescriptor;
10  
11  public class AvoidCatchingThrowableRuleTest extends SimpleAggregatorTst {
12  
13      public void testAll() {
14         runTests(new TestDescriptor[] {
15             new TestDescriptor(TEST1, "simple failure case", 1, new AvoidCatchingThrowable()),
16             new TestDescriptor(TEST2, "ok", 0, new AvoidCatchingThrowable()),
17         });
18      }
19  
20      private static final String TEST1 =
21      "public class Foo {" + PMD.EOL +
22      " void foo() {" + PMD.EOL +
23      "  try {} catch (Throwable t) {}   " + PMD.EOL +
24      " }" + PMD.EOL +
25      "}";
26  
27      private static final String TEST2 =
28      "public class Foo {" + PMD.EOL +
29      " void foo() {" + PMD.EOL +
30      "  try {} catch (RuntimeException t) {}   " + PMD.EOL +
31      " }" + PMD.EOL +
32      "}";
33  }