1 package net.sourceforge.pmd.properties;
2
3 import java.util.Comparator;
4 import java.util.HashMap;
5 import java.util.Map;
6 import java.util.Observer;
7 import java.util.Set;
8
9 import net.sourceforge.pmd.PropertyDescriptor;
10 import net.sourceforge.pmd.lang.rule.properties.TypeMultiProperty;
11 import net.sourceforge.pmd.lang.rule.properties.TypeProperty;
12
13
14
15
16
17
18
19
20
21
22
23
24 public class TypePropertyTest extends AbstractPropertyDescriptorTester {
25
26 private static final Class[] javaLangClasses = new Class[] { String.class, Integer.class, Thread.class,
27 Object.class, Runtime.class };
28 private static final Class[] javaUtilTypes = new Class[] { HashMap.class, Map.class, Comparator.class, Set.class,
29 Observer.class };
30
31 public TypePropertyTest() {
32 super("Class");
33 }
34
35
36
37
38
39
40
41 protected Object createValue(int count) {
42
43 if (count == 1)
44 return randomChoice(javaLangClasses);
45
46 Object[] values = new Object[count];
47 for (int i = 0; i < values.length; i++)
48 values[i] = createValue(1);
49 return values;
50 }
51
52
53
54
55
56
57
58 protected Object createBadValue(int count) {
59
60 if (count == 1)
61 return randomChoice(javaUtilTypes);
62
63 Object[] values = new Object[count];
64 for (int i = 0; i < values.length; i++)
65 values[i] = createBadValue(1);
66 return values;
67 }
68
69
70
71
72
73
74
75 protected PropertyDescriptor createProperty(boolean multiValue) {
76
77 return multiValue ? new TypeMultiProperty("testType", "Test type property", javaLangClasses,
78 new String[] { "java.lang" }, 1.0f) : new TypeProperty("testType", "Test type property",
79 javaLangClasses[0], new String[] { "java.lang" }, 1.0f);
80 }
81
82
83
84
85
86
87
88 protected PropertyDescriptor createBadProperty(boolean multiValue) {
89
90 return multiValue ? new TypeMultiProperty("testType", "Test type property", new Class[] { Set.class },
91 new String[] { "java.lang" }, 1.0f) : new TypeProperty("testType", "Test type property",
92 javaLangClasses[0], new String[] { "java.util" }, 1.0f);
93 }
94
95 }