1 package net.sourceforge.pmd.properties;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5
6 import net.sourceforge.pmd.PropertyDescriptor;
7 import net.sourceforge.pmd.lang.rule.properties.EnumeratedMultiProperty;
8 import net.sourceforge.pmd.lang.rule.properties.EnumeratedProperty;
9
10
11
12
13
14
15
16 public class EnumeratedPropertyTest extends AbstractPropertyDescriptorTester {
17
18 private static final String[] keys = new String[] {
19 "map",
20 "emptyArray",
21 "list",
22 "string",
23 };
24
25 private static final Object[] values = new Object[] {
26 new HashMap(),
27 new Object[0],
28 new ArrayList(),
29 "Hello World!",
30 };
31
32 public EnumeratedPropertyTest() {
33 super();
34 }
35
36
37
38
39
40
41 protected Object createValue(int count) {
42
43 if (count == 1) return randomChoice(values);
44
45 Object[] values = new Object[count];
46 for (int i=0; i<values.length; i++) values[i] = createValue(1);
47 return values;
48 }
49
50
51
52
53
54
55
56 protected Object createBadValue(int count) {
57
58 if (count == 1) return Integer.toString(randomInt());
59
60 Object[] values = new Object[count];
61 for (int i=0; i<values.length; i++) values[i] = createBadValue(1);
62 return values;
63 }
64
65
66
67
68
69
70 protected PropertyDescriptor createProperty(boolean multiValue) {
71
72 return multiValue ?
73 new EnumeratedMultiProperty<Object>("testEnumerations", "Test enumerations with complex types", keys, values, new int[] {0,1}, 1.0f) :
74 new EnumeratedProperty<Object>("testEnumerations", "Test enumerations with complex types", keys, values, 0, 1.0f);
75 }
76
77
78
79
80
81
82 protected PropertyDescriptor createBadProperty(boolean multiValue) {
83
84 return multiValue ?
85 new EnumeratedMultiProperty<Object>("testEnumerations", "Test enumerations with complex types", keys, new Object[0], new int[] {99}, 1.0f) :
86 new EnumeratedProperty<Object>("testEnumerations", "Test enumerations with complex types", new String[0], values, -1, 1.0f);
87 }
88
89 public static junit.framework.Test suite() {
90 return new junit.framework.JUnit4TestAdapter(EnumeratedPropertyTest.class);
91 }
92 }