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 Object[][] mixedItems = new Object[][] {
14 {"map", new HashMap()},
15 {"emptyArray", new Object[0]},
16 {"list", new ArrayList()},
17 {"string", "Hello World!"},
18 };
19
20 public EnumeratedPropertyTest() {
21 super();
22 }
23
24 /***
25 * Method createValue.
26 * @param count int
27 * @return Object
28 */
29 protected Object createValue(int count) {
30
31 if (count == 1) return ((Object[])randomChoice(mixedItems))[1];
32
33 Object[] values = new Object[count];
34 for (int i=0; i<values.length; i++) values[i] = createValue(1);
35 return values;
36 }
37
38 /***
39 * Method createProperty.
40 * @param maxCount int
41 * @return PropertyDescriptor
42 */
43 protected PropertyDescriptor createProperty(int maxCount) {
44
45 return maxCount == 1 ?
46 new EnumeratedProperty("testEnumerations", "Test enumerations with complex types", mixedItems, 1.0f) :
47 new EnumeratedProperty("testEnumerations", "Test enumerations with complex types", mixedItems, 1.0f, 3);
48 }
49
50 }