1   /***
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3   */
4   package test.net.sourceforge.pmd.rules;
5   
6   import net.sourceforge.pmd.PMD;
7   import net.sourceforge.pmd.Rule;
8   import net.sourceforge.pmd.RuleSetNotFoundException;
9   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
10  import test.net.sourceforge.pmd.testframework.TestDescriptor;
11  
12  public class MissingStaticMethodInNonInstantiatableClassTest extends SimpleAggregatorTst {
13      private Rule rule;
14  
15      public void setUp() throws RuleSetNotFoundException {
16          rule = findRule("design", "MissingStaticMethodInNonInstantiatableClass");
17      }
18      
19      public void testAll() {
20         runTests(new TestDescriptor[] {
21                 new TestDescriptor(TEST1, "ok", 0, rule),
22                 new TestDescriptor(TEST2, "ok, default constructor", 0, rule),
23                 new TestDescriptor(TEST3, "simple failure", 1, rule),
24                 new TestDescriptor(TEST4, "failure with multiple constructors", 1, rule),
25                 new TestDescriptor(TEST5, "protected constructor is ok", 0, rule),
26                 new TestDescriptor(TEST6, "ok, one static method", 0, rule),
27                 new TestDescriptor(TEST7, "nested class", 0, rule),
28         });
29      }
30      
31      private static final String TEST1 =
32          "public class Foo {" + PMD.EOL +
33          "}";
34      
35      private static final String TEST2 =
36          "public class Foo {" + PMD.EOL +
37          " public void bar() {} " + PMD.EOL +
38          "}";
39  
40      private static final String TEST3 =
41          "public class Foo {" + PMD.EOL +
42          " private Foo() {}" + PMD.EOL +
43          " public void bar() {}" + PMD.EOL +
44          "}";
45  
46      private static final String TEST4 =
47          "public class Foo {" + PMD.EOL +
48          " private Foo(){}" + PMD.EOL +
49          " private Foo(Object o){}" + PMD.EOL +
50          " public void bar() {} " + PMD.EOL +
51          "}";
52  
53      private static final String TEST5 =
54          "public class Foo {" + PMD.EOL +
55          " private Foo(){}" + PMD.EOL +
56          " protected Foo(Object o){}" + PMD.EOL +
57          " public void bar() {} " + PMD.EOL +
58          "}";
59  
60      private static final String TEST6 =
61          "public class Foo {" + PMD.EOL +
62          " private Foo(){}" + PMD.EOL +
63          " private Foo(Object o){}" + PMD.EOL +
64          " public static void bar() {} " + PMD.EOL +
65          "}";
66  
67      private static final String TEST7 =
68          "public class Foo {" + PMD.EOL +
69          " private static class Bar {" + PMD.EOL +
70          "  private Bar() {}" + PMD.EOL +
71          " }" + PMD.EOL +
72          "}";
73  
74  }