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 public class PropertyAccessorTest extends SimpleAggregatorTst {
25
26 private Rule rule;
27
28 @Before
29 public void setUpSingleRule() {
30 rule = new NonRuleWithAllPropertyTypes();
31 }
32
33 @Test
34 public void testIntegers() {
35 rule.setProperty(NonRuleWithAllPropertyTypes.singleInt, NumericConstants.ZERO);
36 assertSame(rule.getProperty(NonRuleWithAllPropertyTypes.singleInt), 0);
37
38 rule.setProperty(NonRuleWithAllPropertyTypes.multiInt, new Integer[] { NumericConstants.ZERO,
39 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 @Test
76 public void testStrings() {
77 rule.setProperty(NonRuleWithAllPropertyTypes.singleStr, "brian");
78 assertEquals(rule.getProperty(NonRuleWithAllPropertyTypes.singleStr), "brian");
79
80 rule.setProperty(NonRuleWithAllPropertyTypes.multiStr, new String[] { "hello", "world" });
81 assertTrue(CollectionUtil.arraysAreEqual(rule.getProperty(NonRuleWithAllPropertyTypes.multiStr), new String[] {
82 "hello", "world" }));
83 }
84 }