1   
2    /***
3     * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
4     */
5    package> test.net.sourceforge.pmd.rules.strings;
6    
7    import java.util.Set;
8    
9    import net.sourceforge.pmd.Rule;
10   import net.sourceforge.pmd.rules.strings.AvoidDuplicateLiteralsRule;
11   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
12   
13   public class AvoidDuplicateLiteralsRuleTest extends SimpleAggregatorTst {
14       public void testAll() {
15           Rule rule = findRule("strings", "AvoidDuplicateLiterals");
16           rule.addProperty("threshold", "2");
17           runTests(rule);
18       }
19   
20       public void testStringParserEmptyString() {
21           AvoidDuplicateLiteralsRule.ExceptionParser p = new AvoidDuplicateLiteralsRule.ExceptionParser(',');
22           Set res = p.parse("");
23           assertTrue(res.isEmpty());
24       }
25   
26       public void testStringParserSimple() {
27           AvoidDuplicateLiteralsRule.ExceptionParser p = new AvoidDuplicateLiteralsRule.ExceptionParser(',');
28           Set res = p.parse("a,b,c");
29           assertEquals(3, res.size());
30           assertTrue(res.contains("a"));
31           assertTrue(res.contains("b"));
32           assertTrue(res.contains("c"));
33       }
34   
35       public void testStringParserEscapedChar() {
36           AvoidDuplicateLiteralsRule.ExceptionParser p = new AvoidDuplicateLiteralsRule.ExceptionParser(',');
37           Set res = p.parse("a,b,//,");
38           assertEquals(3, res.size());
39           assertTrue(res.contains("a"));
40           assertTrue(res.contains("b"));
41           assertTrue(res.contains(","));
42       }
43   
44       public void testStringParserEscapedEscapedChar() {
45           AvoidDuplicateLiteralsRule.ExceptionParser p = new AvoidDuplicateLiteralsRule.ExceptionParser(',');
46           Set res = p.parse("a,b,////");
47           assertEquals(3, res.size());
48           assertTrue(res.contains("a"));
49           assertTrue(res.contains("b"));
50           assertTrue(res.contains("//"));
51       }
52   }