    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.Report;
    8   import net.sourceforge.pmd.Rule;
    9   import net.sourceforge.pmd.RuleSetNotFoundException;
    10  import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
    11  import test.net.sourceforge.pmd.testframework.TestDescriptor;
    12
    13  public class ExceptionSignatureDeclarationRuleTest extends SimpleAggregatorTst {
    14
    15      private Rule rule;
    16
    17      public void setUp() throws RuleSetNotFoundException {
    18          rule = findRule("strictexception", "SignatureDeclareThrowsException");
    19      }
    20
    21      public void testAll() {
    22          runTests(new TestDescriptor[]{
    23              new TestDescriptor(TEST1, "method throws Exception", 1, rule),
    24              new TestDescriptor(TEST2, "ok", 0, rule),
    25              new TestDescriptor(TEST3, "constructor throws Exception", 1, rule),
    26              new TestDescriptor(TEST4, "skip junit setUp method", 0, rule),
    27              new TestDescriptor(TEST5, "skip junit tearDown method", 0, rule),
    28          });
    29      }
    30
    31      public void testGenerics() throws Throwable {
    32          Report rpt = new Report();
    33          runTestFromString15(TEST6, rule, rpt);
    34          assertEquals(0, rpt.size());
    35      }
    36
    37      private static final String TEST1 =
    38              "public class Foo {" + PMD.EOL +
    39              " void foo() throws Exception {}" + PMD.EOL +
    40              "}";
    41
    42      private static final String TEST2 =
    43              "public class Foo {" + PMD.EOL +
    44              " void foo() {}" + PMD.EOL +
    45              "}";
    46
    47      private static final String TEST3 =
    48              "public class Foo {" + PMD.EOL +
    49              " Foo() throws Exception {}" + PMD.EOL +
    50              "}";
    51
    52      private static final String TEST4 =
    53              "import junit.framework.*;" + PMD.EOL +
    54              "public class Foo {" + PMD.EOL +
    55              " void setUp() throws Exception {}" + PMD.EOL +
    56              "}";
    57
    58      private static final String TEST5 =
    59              "import junit.framework.*;" + PMD.EOL +
    60              "public class Foo {" + PMD.EOL +
    61              " void tearDown() throws Exception {}" + PMD.EOL +
    62              "}";
    63
    64      private static final String TEST6 =
    65              "public class Foo {" + PMD.EOL +
    66              " public <T> Bar<T> foo() { /* blah */}" + PMD.EOL +
    67              "}";
    68
    69  }