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, "don't flag toUpperCase() invocations with Locale args", 0, rule),
22              //new TestDescriptor(TEST5, "failure case with array", 1, rule),
23          });
24      }
25  
26      private static final String TEST1 =
27              "public class Foo {" + PMD.EOL +
28              " private boolean baz(String buz) {" + PMD.EOL +
29              "  return foo.toUpperCase().equals(\"foo\");" + PMD.EOL +
30              " }" + PMD.EOL +
31              "}";
32  
33      private static final String TEST2 =
34              "public class Foo {" + PMD.EOL +
35              " private boolean baz(String buz) {" + PMD.EOL +
36              "  return foo.toLowerCase().equals(\"foo\");" + PMD.EOL +
37              " }" + PMD.EOL +
38              "}";
39  
40      private static final String TEST3 =
41              "public class Foo {" + PMD.EOL +
42              " private boolean baz(String buz) {" + PMD.EOL +
43              "  return foo.toUpperCase().equalsIgnoreCase(\"foo\");" + PMD.EOL +
44              " }" + PMD.EOL +
45              "}";
46  
47      private static final String TEST4 =
48              "public class Foo {" + PMD.EOL +
49              " private boolean baz(String buz) {" + PMD.EOL +
50              "  return foo.toUpperCase(locale).equals(\"foo\");" + PMD.EOL +
51              " }" + PMD.EOL +
52              "}";
53  
54  /*
55     private static final String TEST5 =
56      "public class Foo {" + PMD.EOL +
57      " private boolean baz(String[] buz) {" + PMD.EOL +
58      "  return buz[2].toUpperCase().equalsIgnoreCase(\"foo\");" + PMD.EOL +
59      " }" + PMD.EOL +
60      "}";
61  */
62  
63  }