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