1   package test.net.sourceforge.pmd.rules;
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 SuspiciousConstantFieldNameTest  extends SimpleAggregatorTst {
10      private Rule rule;
11  
12      public void setUp() throws RuleSetNotFoundException {
13          rule = findRule("naming", "SuspiciousConstantFieldName");
14      }
15  
16      public void testAll() {
17         runTests(new TestDescriptor[] {
18             new TestDescriptor(TEST1, "ok", 0, rule),
19             new TestDescriptor(TEST2, "PI not final", 1, rule),
20             new TestDescriptor(TEST3, "PI and E not final", 2, rule),
21             new TestDescriptor(TEST4, "ok", 0, rule),
22             new TestDescriptor(TEST5, "ignore interfaces", 0, rule),
23         });
24      }
25  
26      private static final String TEST1 =
27      "public class Foo {" + PMD.EOL +
28      " public int e;" + PMD.EOL +
29      " public final int PI;" + PMD.EOL +
30      "}";
31  
32      private static final String TEST2 =
33      "public class Foo {" + PMD.EOL +
34      " public int e;" + PMD.EOL +
35      " public int PI;" + PMD.EOL +
36      "}";
37  
38      private static final String TEST3 =
39      "public class Foo {" + PMD.EOL +
40      " public int E;" + PMD.EOL +
41      " public int PI;" + PMD.EOL +
42      "}";
43  
44      private static final String TEST4 =
45      "public class Foo {" + PMD.EOL +
46      " public final int e;" + PMD.EOL +
47      " public final int PI;" + PMD.EOL +
48      "}";
49  
50      private static final String TEST5 =
51      "public interface Foo {" + PMD.EOL +
52      " public int E;" + PMD.EOL +
53      "}";
54  
55  }