1   package test.net.sourceforge.pmd.rules.strings;
2   
3   import net.sourceforge.pmd.PMD;
4   import net.sourceforge.pmd.Rule;
5   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
6   import test.net.sourceforge.pmd.testframework.TestDescriptor;
7   
8   public class UnnecessaryCaseChangeRuleTest extends SimpleAggregatorTst {
9   
10      private Rule rule;
11  
12      public void setUp() throws Exception {
13          rule = findRule("rulesets/strings.xml", "UnnecessaryCaseChange");
14      }
15  
16      public void testAll() {
17         runTests(new TestDescriptor[] {
18             new TestDescriptor(TEST1, "failure case with toUpperCase().equals()", 1, rule),
19             new TestDescriptor(TEST2, "failure case with toLowerCase().equals()", 1, rule),
20             new TestDescriptor(TEST3, "failure case with toUpperCase().equalsIgnoreCase()", 1, rule),
21             //new TestDescriptor(TEST4, "failure case with array", 1, rule),
22         });
23      }
24  
25     private static final String TEST1 =
26      "public class Foo {" + PMD.EOL +
27      " private boolean baz(String buz) {" + PMD.EOL +
28      "  return foo.toUpperCase().equals(\"foo\");" + PMD.EOL +
29      " }" + PMD.EOL +
30      "}";
31  
32     private static final String TEST2 =
33      "public class Foo {" + PMD.EOL +
34      " private boolean baz(String buz) {" + PMD.EOL +
35      "  return foo.toLowerCase().equals(\"foo\");" + PMD.EOL +
36      " }" + PMD.EOL +
37      "}";
38  
39     private static final String TEST3 =
40      "public class Foo {" + PMD.EOL +
41      " private boolean baz(String buz) {" + PMD.EOL +
42      "  return foo.toUpperCase().equalsIgnoreCase(\"foo\");" + PMD.EOL +
43      " }" + PMD.EOL +
44      "}";
45  
46  /*
47     private static final String TEST4 =
48      "public class Foo {" + PMD.EOL +
49      " private boolean baz(String[] buz) {" + PMD.EOL +
50      "  return buz[2].toUpperCase().equalsIgnoreCase(\"foo\");" + PMD.EOL +
51      " }" + PMD.EOL +
52      "}";
53  */
54  
55  }