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