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 import org.junit.Assume;
11 import org.junit.Test;
12
13
14
15
16
17
18
19
20 public class EnumeratedPropertyTest extends AbstractPropertyDescriptorTester {
21
22 private static final String[] keys = new String[] { "map", "emptyArray", "list", "string", };
23
24 private static final Object[] values = new Object[] { new HashMap(), new Object[0], new ArrayList(),
25 "Hello World!", };
26
27 public EnumeratedPropertyTest() {
28 super("Enum");
29 }
30
31
32
33
34
35
36
37 protected Object createValue(int count) {
38
39 if (count == 1)
40 return randomChoice(values);
41
42 Object[] values = new Object[count];
43 for (int i = 0; i < values.length; i++)
44 values[i] = createValue(1);
45 return values;
46 }
47
48
49
50
51
52
53
54
55 protected Object createBadValue(int count) {
56
57 if (count == 1)
58 return Integer.toString(randomInt());
59
60 Object[] values = new Object[count];
61 for (int i = 0; i < values.length; i++)
62 values[i] = createBadValue(1);
63 return values;
64 }
65
66
67
68
69
70
71
72 protected PropertyDescriptor createProperty(boolean multiValue) {
73
74 return multiValue ? new EnumeratedMultiProperty<Object>("testEnumerations",
75 "Test enumerations with complex types", keys, values, new int[] { 0, 1 }, 1.0f)
76 : new EnumeratedProperty<Object>("testEnumerations", "Test enumerations with complex types", keys,
77 values, 0, 1.0f);
78 }
79
80
81
82
83
84
85
86 protected PropertyDescriptor createBadProperty(boolean multiValue) {
87
88 return multiValue ? new EnumeratedMultiProperty<Object>("testEnumerations",
89 "Test enumerations with complex types", keys, new Object[0], new int[] { 99 }, 1.0f)
90 : new EnumeratedProperty<Object>("testEnumerations", "Test enumerations with complex types",
91 new String[0], values, -1, 1.0f);
92 }
93
94 @Test
95 public void testFactorySingleValue() {
96 Assume.assumeTrue("The EnumeratedProperty is not implemented completely yet", false);
97 }
98
99 @Test
100 public void testFactoryMultiValueCustomDelimiter() {
101 Assume.assumeTrue("The EnumeratedProperty is not implemented completely yet", false);
102 }
103
104 @Test
105 public void testFactoryMultiValueDefaultDelimiter() {
106 Assume.assumeTrue("The EnumeratedProperty is not implemented completely yet", false);
107 }
108 }