1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.beanutils;
18
19 import junit.framework.Test;
20 import junit.framework.TestCase;
21 import junit.framework.TestSuite;
22
23 import java.util.Collection;
24
25
26
27
28
29
30 public class DynaPropertyTestCase extends TestCase {
31
32 private DynaProperty testPropertyWithName;
33 private DynaProperty testProperty1Duplicate;
34 private DynaProperty testPropertyWithNameAndType;
35 private DynaProperty testProperty2Duplicate;
36 private DynaProperty testPropertyWithNameAndTypeAndContentType;
37 private DynaProperty testProperty3Duplicate;
38
39
40
41
42
43
44 public DynaPropertyTestCase(String name) {
45 super(name);
46 }
47
48
49
50
51
52 public static Test suite() {
53
54 return (new TestSuite(DynaPropertyTestCase.class));
55
56 }
57
58
59
60
61 protected void setUp() throws Exception {
62
63 super.setUp();
64
65 testPropertyWithName = new DynaProperty("test1");
66 testProperty1Duplicate = new DynaProperty("test1");
67
68 testPropertyWithNameAndType = new DynaProperty("test2", Integer.class);
69 testProperty2Duplicate = new DynaProperty("test2", Integer.class);
70
71 testPropertyWithNameAndTypeAndContentType = new DynaProperty("test3", Collection.class, Short.class);
72 testProperty3Duplicate = new DynaProperty("test3", Collection.class, Short.class);
73 }
74
75
76
77
78 protected void tearDown() throws Exception {
79
80 testPropertyWithName = testProperty1Duplicate = null;
81 testPropertyWithNameAndType = testProperty2Duplicate = null;
82 testPropertyWithNameAndTypeAndContentType = testProperty3Duplicate = null;
83 super.tearDown();
84 }
85
86
87
88
89 public void testHashCode() {
90
91 final int initialHashCode = testPropertyWithNameAndTypeAndContentType.hashCode();
92 assertEquals(testPropertyWithName.hashCode(), testProperty1Duplicate.hashCode());
93 assertEquals(testPropertyWithNameAndType.hashCode(), testProperty2Duplicate.hashCode());
94 assertEquals(testPropertyWithNameAndTypeAndContentType.hashCode(), testProperty3Duplicate.hashCode());
95 assertEquals(initialHashCode, testPropertyWithNameAndTypeAndContentType.hashCode());
96 }
97
98
99
100
101 public void testEqualsObject() {
102
103 assertEquals(testPropertyWithName, testProperty1Duplicate);
104 assertEquals(testPropertyWithNameAndType, testProperty2Duplicate);
105 assertEquals(testPropertyWithNameAndTypeAndContentType, testProperty3Duplicate);
106 assertFalse(testPropertyWithName.equals(testPropertyWithNameAndType));
107 assertFalse(testPropertyWithNameAndType.equals(testPropertyWithNameAndTypeAndContentType));
108 assertFalse(testPropertyWithName.equals(null));
109 }
110
111 }