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              new TestDescriptor(TEST8, "ok, public static field", 0, rule),
29              new TestDescriptor(TEST9, "not ok, non-public static field", 1, rule),
30          });
31      }
32  
33      private static final String TEST1 =
34              "public class Foo {" + PMD.EOL +
35              "}";
36  
37      private static final String TEST2 =
38              "public class Foo {" + PMD.EOL +
39              " public void bar() {} " + PMD.EOL +
40              "}";
41  
42      private static final String TEST3 =
43              "public class Foo {" + PMD.EOL +
44              " private Foo() {}" + PMD.EOL +
45              " public void bar() {}" + PMD.EOL +
46              "}";
47  
48      private static final String TEST4 =
49              "public class Foo {" + PMD.EOL +
50              " private Foo(){}" + PMD.EOL +
51              " private Foo(Object o){}" + PMD.EOL +
52              " public void bar() {} " + PMD.EOL +
53              "}";
54  
55      private static final String TEST5 =
56              "public class Foo {" + PMD.EOL +
57              " private Foo(){}" + PMD.EOL +
58              " protected Foo(Object o){}" + PMD.EOL +
59              " public void bar() {} " + PMD.EOL +
60              "}";
61  
62      private static final String TEST6 =
63              "public class Foo {" + PMD.EOL +
64              " private Foo(){}" + PMD.EOL +
65              " private Foo(Object o){}" + PMD.EOL +
66              " public static void bar() {} " + PMD.EOL +
67              "}";
68  
69      private static final String TEST7 =
70              "public class Foo {" + PMD.EOL +
71              " private static class Bar {" + PMD.EOL +
72              "  private Bar() {}" + PMD.EOL +
73              " }" + PMD.EOL +
74              "}";
75  
76      private static final String TEST8 =
77              "public class Foo {" + PMD.EOL +
78              " public static int BUZ = 2;" + PMD.EOL +
79              "  private Foo() {}" + PMD.EOL +
80              "}";
81  
82      private static final String TEST9 =
83              "public class Foo {" + PMD.EOL +
84              " private static int BUZ = 2;" + PMD.EOL +
85              "  private Foo() {}" + PMD.EOL +
86              "}";
87  
88  }