1 package net.sourceforge.pmd.properties;
2
3 import net.sourceforge.pmd.PropertyDescriptor;
4 import net.sourceforge.pmd.lang.rule.properties.StringMultiProperty;
5 import net.sourceforge.pmd.lang.rule.properties.StringProperty;
6
7
8
9
10
11
12
13
14 public class StringPropertyTest extends AbstractPropertyDescriptorTester {
15
16 private static final int maxStringLength = 52;
17 private static final char delimiter = '|';
18 private static final char[] charSet = filter(allChars.toCharArray(), delimiter);
19
20 public StringPropertyTest() {
21 super();
22 }
23
24
25
26
27
28
29 protected Object createValue(int count) {
30
31 if (count == 1) return newString();
32
33 String[] values = new String[count];
34 for (int i=0; i<count; i++) values[i] = (String)createValue(1);
35 return values;
36 }
37
38
39
40
41
42
43 protected Object createBadValue(int count) {
44
45 if (count == 1) return null;
46
47 Object[] values = new Object[count];
48 for (int i=0; i<count; i++) values[i] = createBadValue(1);
49 return values;
50 }
51
52
53
54
55
56 private String newString() {
57
58 int strLength = randomInt(0, maxStringLength);
59
60 char[] chars = new char[strLength];
61 for (int i=0; i<chars.length; i++) chars[i] = randomCharIn(charSet);
62 return new String(chars);
63 }
64
65
66
67
68
69
70 private char randomCharIn(char[] chars) {
71 return randomChar(chars);
72 }
73
74
75
76
77
78
79 protected PropertyDescriptor createProperty(boolean multiValue) {
80 return multiValue ?
81 new StringMultiProperty("testString", "Test string property", new String[] {"hello", "world"}, 1.0f, delimiter) :
82 new StringProperty("testString", "Test string property", "brian", 1.0f);
83 }
84
85
86
87
88
89
90 protected PropertyDescriptor createBadProperty(boolean multiValue) {
91 return multiValue ?
92 new StringMultiProperty("testString", "Test string property", new String[] {"hello", "world", "a"+delimiter+"b"}, 1.0f, delimiter) :
93 new StringProperty("", "Test string property", "brian", 1.0f);
94 }
95
96 public static junit.framework.Test suite() {
97 return new junit.framework.JUnit4TestAdapter(StringPropertyTest.class);
98 }
99 }