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.util.CollectionUtil;
14 import net.sourceforge.pmd.util.NumericConstants;
15
16 import org.junit.Before;
17 import org.junit.Ignore;
18 import org.junit.Test;
19
20
21
22
23 public class PropertyAccessorTest {
24
25 private Rule rule;
26
27 @Before
28 public void setUpSingleRule() {
29 rule = new NonRuleWithAllPropertyTypes();
30 }
31
32 @Test
33 public void testIntegers() {
34 rule.setProperty(NonRuleWithAllPropertyTypes.singleInt, NumericConstants.ZERO);
35 assertSame(rule.getProperty(NonRuleWithAllPropertyTypes.singleInt), 0);
36
37 rule.setProperty(NonRuleWithAllPropertyTypes.multiInt, new Integer[] { NumericConstants.ZERO,
38 NumericConstants.ONE });
39 assertArrayEquals(rule.getProperty(NonRuleWithAllPropertyTypes.multiInt), new Integer[] { 0, 1 });
40 }
41
42 @Test
43 public void testBooleans() {
44
45 rule.setProperty(NonRuleWithAllPropertyTypes.singleBool, Boolean.FALSE);
46 assertFalse(rule.getProperty(NonRuleWithAllPropertyTypes.singleBool));
47
48 rule.setProperty(NonRuleWithAllPropertyTypes.multiBool, new Boolean[] { Boolean.TRUE, Boolean.FALSE });
49 assertArrayEquals(rule.getProperty(NonRuleWithAllPropertyTypes.multiBool), new Boolean[] { true, false });
50 }
51
52 @Ignore
53 @Test
54 public void testFloats() throws ReportException {
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 }
73
74 @Test
75 public void testStrings() {
76 rule.setProperty(NonRuleWithAllPropertyTypes.singleStr, "brian");
77 assertEquals(rule.getProperty(NonRuleWithAllPropertyTypes.singleStr), "brian");
78
79 rule.setProperty(NonRuleWithAllPropertyTypes.multiStr, new String[] { "hello", "world" });
80 assertTrue(CollectionUtil.arraysAreEqual(rule.getProperty(NonRuleWithAllPropertyTypes.multiStr), new String[] {
81 "hello", "world" }));
82 }
83 }