1 package test.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.properties.EnumeratedProperty;
8
9 /**
10 */
11 public class EnumeratedPropertyTest extends AbstractPropertyDescriptorTester {
12
13 private static final String[] keys = new String[] {
14 "map",
15 "emptyArray",
16 "list",
17 "string",
18 };
19
20 private static final Object[] values = new Object[] {
21 new HashMap(),
22 new Object[0],
23 new ArrayList(),
24 "Hello World!",
25 };
26
27 public EnumeratedPropertyTest() {
28 super();
29 }
30
31 /**
32 * Method createValue.
33 * @param count int
34 * @return Object
35 */
36 protected Object createValue(int count) {
37
38 if (count == 1) return randomChoice(values);
39
40 Object[] values = new Object[count];
41 for (int i=0; i<values.length; i++) values[i] = createValue(1);
42 return values;
43 }
44
45 /**
46 * Method createProperty.
47 * @param maxCount int
48 * @return PropertyDescriptor
49 */
50 protected PropertyDescriptor createProperty(int maxCount) {
51
52 return maxCount == 1 ?
53 new EnumeratedProperty<Object>("testEnumerations", "Test enumerations with complex types", keys, values, 1.0f) :
54 new EnumeratedProperty<Object>("testEnumerations", "Test enumerations with complex types", keys, values, 1.0f, 3);
55 }
56
57 public static junit.framework.Test suite() {
58 return new junit.framework.JUnit4TestAdapter(EnumeratedPropertyTest.class);
59 }
60 }