1 package test.net.sourceforge.pmd.rules;
2
3 import net.sourceforge.pmd.PMD;
4 import net.sourceforge.pmd.rules.AvoidDuplicateLiteralsRule;
5
6 public class AvoidDuplicateLiteralsRuleTest extends RuleTst {
7
8 public static final String TEST1 =
9 "public class Foo {" + PMD.EOL +
10 " private void bar() {" + PMD.EOL +
11 " buz(\"Howdy\");" + PMD.EOL +
12 " buz(\"Howdy\");" + PMD.EOL +
13 " buz(\"Howdy\");" + PMD.EOL +
14 " buz(\"Howdy\");" + PMD.EOL +
15 " }" + PMD.EOL +
16 " private void buz(String x) {}" + PMD.EOL +
17 "}";
18
19 public static final String TEST2 =
20 "public class Foo {" + PMD.EOL +
21 " private void bar() {" + PMD.EOL +
22 " buz(2);" + PMD.EOL +
23 " }" + PMD.EOL +
24 " private void buz(int x) {}" + PMD.EOL +
25 "}";
26
27 public static final String TEST3 =
28 "public class Foo {" + PMD.EOL +
29 " private static final String FOO = \"foo\";" + PMD.EOL +
30 "}";
31
32 private AvoidDuplicateLiteralsRule rule;
33
34 public void setUp() {
35 rule = new AvoidDuplicateLiteralsRule();
36 rule.setMessage("avoid ''{0}'' and ''{1}''");
37 rule.addProperty("threshold", "2");
38 }
39
40 public void testTwoLiteralStringArgs() throws Throwable {
41 runTestFromString(TEST1, 1, rule);
42 }
43 public void testLiteralIntArg() throws Throwable {
44 runTestFromString(TEST2, 0, rule);
45 }
46 public void testLiteralFieldDecl() throws Throwable {
47 runTestFromString(TEST3, 0, rule);
48 }
49 }
This page was automatically generated by Maven