1 package net.sourceforge.pmd.properties;
2
3 import net.sourceforge.pmd.PropertyDescriptor;
4 import net.sourceforge.pmd.lang.rule.properties.IntegerMultiProperty;
5 import net.sourceforge.pmd.lang.rule.properties.IntegerProperty;
6
7 import org.junit.Test;
8
9
10
11
12
13
14
15
16 public class IntegerPropertyTest extends AbstractPropertyDescriptorTester {
17
18 private static final int MIN = 1;
19 private static final int MAX = 12;
20 private static final int SHIFT = 3;
21
22
23
24
25
26
27 protected Object createValue(int count) {
28
29 if (count == 1) return Integer.valueOf(randomInt(MIN, MAX));
30
31 Integer[] values = new Integer[count];
32 for (int i=0; i<values.length; i++) values[i] = (Integer)createValue(1);
33 return values;
34 }
35
36
37
38
39
40
41
42 protected Object createBadValue(int count) {
43
44 if (count == 1) return Integer.valueOf(
45 randomBool() ?
46 randomInt(MIN - SHIFT, MIN) :
47 randomInt(MAX, MAX + SHIFT)
48 );
49
50 Integer[] values = new Integer[count];
51 for (int i=0; i<values.length; i++) values[i] = (Integer)createBadValue(1);
52 return values;
53 }
54
55 @Test
56 public void testErrorForBad() { }
57
58
59
60
61
62
63 protected PropertyDescriptor createProperty(boolean multiValue) {
64
65 return multiValue ?
66 new IntegerMultiProperty("testInteger", "Test integer property", MIN, MAX, new Integer[] {MIN, MIN+1, MAX-1, MAX}, 1.0f) :
67 new IntegerProperty("testInteger", "Test integer property", MIN, MAX, MAX-1, 1.0f);
68 }
69
70
71
72
73
74
75 protected PropertyDescriptor createBadProperty(boolean multiValue) {
76
77 return multiValue ?
78 new IntegerMultiProperty("testInteger", "", MIN, MAX, new Integer[] {MIN-1, MAX}, 1.0f) :
79 new IntegerProperty("", "Test integer property", MIN, MAX, MAX+1, 1.0f);
80 }
81
82 public static junit.framework.Test suite() {
83 return new junit.framework.JUnit4TestAdapter(IntegerPropertyTest.class);
84 }
85 }