1
2
3
4 package net.sourceforge.pmd.properties;
5
6 import static org.junit.Assert.assertArrayEquals;
7 import static org.junit.Assert.assertEquals;
8 import static org.junit.Assert.assertFalse;
9 import static org.junit.Assert.assertSame;
10 import static org.junit.Assert.assertTrue;
11 import net.sourceforge.pmd.Rule;
12 import net.sourceforge.pmd.cpd.ReportException;
13 import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
14 import net.sourceforge.pmd.util.CollectionUtil;
15 import net.sourceforge.pmd.util.NumericConstants;
16
17 import org.junit.Before;
18 import org.junit.Ignore;
19 import org.junit.Test;
20
21
22
23
24
25 public class PropertyAccessorTest extends SimpleAggregatorTst {
26
27 private Rule rule;
28
29 @Before
30 public void setUp() {
31 rule = new NonRuleWithAllPropertyTypes();
32 }
33
34 @Test
35 public void testIntegers() {
36 rule.setProperty(NonRuleWithAllPropertyTypes.singleInt, NumericConstants.ZERO);
37 assertSame(rule.getProperty(NonRuleWithAllPropertyTypes.singleInt), 0);
38
39 rule.setProperty(NonRuleWithAllPropertyTypes.multiInt, new Integer[] {NumericConstants.ZERO, NumericConstants.ONE});
40 assertArrayEquals(rule.getProperty(NonRuleWithAllPropertyTypes.multiInt), new Integer[]{0, 1});
41 }
42
43 @Test
44 public void testBooleans() {
45
46 rule.setProperty(NonRuleWithAllPropertyTypes.singleBool, Boolean.FALSE);
47 assertFalse(rule.getProperty(NonRuleWithAllPropertyTypes.singleBool));
48
49 rule.setProperty(NonRuleWithAllPropertyTypes.multiBool, new Boolean[] {Boolean.TRUE, Boolean.FALSE});
50 assertArrayEquals(rule.getProperty(NonRuleWithAllPropertyTypes.multiBool), new Boolean[]{true, false});
51 }
52
53 @Ignore
54 @Test
55 public void testFloats() throws ReportException {
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 }
79
80 @Test
81 public void testStrings() {
82 rule.setProperty(NonRuleWithAllPropertyTypes.singleStr, "brian");
83 assertEquals(rule.getProperty(NonRuleWithAllPropertyTypes.singleStr), "brian");
84
85 rule.setProperty(NonRuleWithAllPropertyTypes.multiStr, new String[] {"hello", "world"});
86 assertTrue(CollectionUtil.arraysAreEqual(rule.getProperty(NonRuleWithAllPropertyTypes.multiStr), new String[] {"hello", "world"}));
87 }
88
89 public static junit.framework.Test suite() {
90 return new junit.framework.JUnit4TestAdapter(PropertyAccessorTest.class);
91 }
92 }