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 public class TypePropertyTest extends AbstractPropertyDescriptorTester {
24
25 private static final Class[] javaLangClasses = new Class[] { String.class, Integer.class, Thread.class, Object.class, Runtime.class };
26 private static final Class[] javaUtilTypes = new Class[] { HashMap.class, Map.class, Comparator.class, Set.class, Observer.class };
27
28 public TypePropertyTest() {
29 super();
30 }
31
32
33
34
35
36
37 protected Object createValue(int count) {
38
39 if (count == 1) return randomChoice(javaLangClasses);
40
41 Object[] values = new Object[count];
42 for (int i=0; i<values.length; i++) values[i] = createValue(1);
43 return values;
44 }
45
46
47
48
49
50
51 protected Object createBadValue(int count) {
52
53 if (count == 1) return randomChoice(javaUtilTypes);
54
55 Object[] values = new Object[count];
56 for (int i=0; i<values.length; i++) values[i] = createBadValue(1);
57 return values;
58 }
59
60
61
62
63
64
65 protected PropertyDescriptor createProperty(boolean multiValue) {
66
67 return multiValue ?
68 new TypeMultiProperty("testType", "Test type property", javaLangClasses, new String[] { "java.lang" }, 1.0f) :
69 new TypeProperty("testType", "Test type property", javaLangClasses[0], new String[] { "java.lang" }, 1.0f);
70 }
71
72
73
74
75
76
77 protected PropertyDescriptor createBadProperty(boolean multiValue) {
78
79 return multiValue ?
80 new TypeMultiProperty("testType", "Test type property", new Class[]{Set.class}, new String[] { "java.lang" }, 1.0f) :
81 new TypeProperty("testType", "Test type property", javaLangClasses[0], new String[] { "java.util" }, 1.0f);
82 }
83
84 public static junit.framework.Test suite() {
85 return new junit.framework.JUnit4TestAdapter(TypePropertyTest.class);
86 }
87 }