01: /**
02: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
03: */package test.net.sourceforge.pmd.rules.strings;
04:
05: import static org.junit.Assert.assertEquals;
06: import static org.junit.Assert.assertTrue;
07: import net.sourceforge.pmd.Rule;
08: import net.sourceforge.pmd.rules.strings.AvoidDuplicateLiteralsRule;
09:
10: import org.junit.Test;
11:
12: import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
13:
14: import java.util.Set;
15:
16: public class AvoidDuplicateLiteralsRuleTest extends SimpleAggregatorTst {
17:
18: @Test
19: public void testAll() {
20: Rule rule = findRule("strings", "AvoidDuplicateLiterals");
21: rule.addProperty("threshold", "2");
22: runTests(rule);
23: }
24:
25: @Test
26: public void testStringParserEmptyString() {
27: AvoidDuplicateLiteralsRule.ExceptionParser p = new AvoidDuplicateLiteralsRule.ExceptionParser(
28: ',');
29: Set res = p.parse("");
30: assertTrue(res.isEmpty());
31: }
32:
33: @Test
34: public void testStringParserSimple() {
35: AvoidDuplicateLiteralsRule.ExceptionParser p = new AvoidDuplicateLiteralsRule.ExceptionParser(
36: ',');
37: Set res = p.parse("a,b,c");
38: assertEquals(3, res.size());
39: assertTrue(res.contains("a"));
40: assertTrue(res.contains("b"));
41: assertTrue(res.contains("c"));
42: }
43:
44: @Test
45: public void testStringParserEscapedChar() {
46: AvoidDuplicateLiteralsRule.ExceptionParser p = new AvoidDuplicateLiteralsRule.ExceptionParser(
47: ',');
48: Set res = p.parse("a,b,\\,");
49: assertEquals(3, res.size());
50: assertTrue(res.contains("a"));
51: assertTrue(res.contains("b"));
52: assertTrue(res.contains(","));
53: }
54:
55: @Test
56: public void testStringParserEscapedEscapedChar() {
57: AvoidDuplicateLiteralsRule.ExceptionParser p = new AvoidDuplicateLiteralsRule.ExceptionParser(
58: ',');
59: Set res = p.parse("a,b,\\\\");
60: assertEquals(3, res.size());
61: assertTrue(res.contains("a"));
62: assertTrue(res.contains("b"));
63: assertTrue(res.contains("\\"));
64: }
65:
66: public static junit.framework.Test suite() {
67: return new junit.framework.JUnit4TestAdapter(
68: AvoidDuplicateLiteralsRuleTest.class);
69: }
70: }
|