1   package test.net.sourceforge.pmd.rules.clone;
2   
3   import net.sourceforge.pmd.PMD;
4   import net.sourceforge.pmd.Rule;
5   import net.sourceforge.pmd.RuleSetNotFoundException;
6   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
7   import test.net.sourceforge.pmd.testframework.TestDescriptor;
8   
9   public class CloneThrowsCloneNotSupportedExceptionTest extends SimpleAggregatorTst {
10  
11      private Rule rule;
12  
13      public void setUp() throws RuleSetNotFoundException {
14          rule = findRule("clone", "CloneThrowsCloneNotSupportedException");
15      }
16  
17      public void testAll() {
18          runTests(new TestDescriptor[]{
19              new TestDescriptor(TEST1, "ok, throws CloneNotSupportedException", 0, rule),
20              new TestDescriptor(TEST2, "bad", 1, rule),
21              new TestDescriptor(TEST3, "final class, rule does not apply", 0, rule),
22              new TestDescriptor(TEST4, "testing with multiple methods", 1, rule),
23          });
24      }
25  
26      private static final String TEST1 =
27              "public class Foo {" + PMD.EOL +
28              " void clone() throws CloneNotSupportedException {" + PMD.EOL +
29              " }" + PMD.EOL +
30              "}";
31  
32      private static final String TEST2 =
33              "public class Foo {" + PMD.EOL +
34              " void clone() {" + PMD.EOL +
35              " }" + PMD.EOL +
36              "}";
37  
38      private static final String TEST3 =
39              "public final class Foo {" + PMD.EOL +
40              " void clone() {" + PMD.EOL +
41              " }" + PMD.EOL +
42              "}";
43  
44      private static final String TEST4 =
45              "public class Foo {" + PMD.EOL +
46              " void clone() {}" + PMD.EOL +
47              " void foo() {}" + PMD.EOL +
48              " void bar() {}" + PMD.EOL +
49              "}";
50  }