01: package test.net.sourceforge.pmd.properties;
02:
03: import net.sourceforge.pmd.PropertyDescriptor;
04: import net.sourceforge.pmd.properties.StringProperty;
05:
06: /**
07: */
08: public class StringPropertyTest extends
09: AbstractPropertyDescriptorTester {
10:
11: private static final int maxStringLength = 52;
12: private static final char delimiter = '|';
13: private static final char[] charSet = filter(
14: allChars.toCharArray(), delimiter);
15:
16: public StringPropertyTest() {
17: super ();
18: }
19:
20: /**
21: * Method createValue.
22: * @param count int
23: * @return Object
24: */
25: protected Object createValue(int count) {
26:
27: if (count == 1)
28: return newString();
29:
30: String[] values = new String[count];
31: for (int i = 0; i < count; i++)
32: values[i] = (String) createValue(1);
33: return values;
34: }
35:
36: /**
37: * Method newString.
38: * @return String
39: */
40: private String newString() {
41:
42: int strLength = randomInt(0, maxStringLength);
43:
44: char[] chars = new char[strLength];
45: for (int i = 0; i < chars.length; i++)
46: chars[i] = randomCharIn(charSet);
47: return new String(chars);
48: }
49:
50: /**
51: * Method randomCharIn.
52: * @param chars char[]
53: * @return char
54: */
55: private char randomCharIn(char[] chars) {
56: return randomChar(chars);
57: }
58:
59: /**
60: * Method createProperty.
61: * @param maxCount int
62: * @return PropertyDescriptor
63: */
64: protected PropertyDescriptor createProperty(int maxCount) {
65: return maxCount == 1 ? new StringProperty("testString",
66: "Test string property", "brian", 1.0f)
67: : new StringProperty("testString",
68: "Test string property", new String[] { "hello",
69: "world" }, 1.0f, delimiter);
70: }
71:
72: public static junit.framework.Test suite() {
73: return new junit.framework.JUnit4TestAdapter(
74: StringPropertyTest.class);
75: }
76: }
|