1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jdtaus.core.container.test;
22
23 import java.io.ObjectInputStream;
24 import junit.framework.Assert;
25 import junit.framework.TestCase;
26 import org.jdtaus.core.container.Properties;
27 import org.jdtaus.core.container.Property;
28
29
30
31
32
33
34
35 public class PropertiesTest extends TestCase
36 {
37
38
39 public void testObject() throws Exception
40 {
41 final Properties p1 = new Properties();
42 final Properties p2 = new Properties();
43
44 Assert.assertEquals( p1, p2 );
45 Assert.assertEquals( p1.hashCode(), p2.hashCode() );
46
47 System.out.println( p1.toString() );
48 System.out.println( p2.toString() );
49
50 final Property[] prop1 =
51 {
52 new Property(), new Property(), new Property()
53 };
54 final Property[] prop2 =
55 {
56 new Property(), new Property(), new Property()
57 };
58 final Property[] prop3 =
59 {
60 new Property(), new Property(), new Property()
61 };
62 final Property[] prop4 =
63 {
64 new Property(), new Property()
65 };
66
67 prop1[0].setName( "TEST 1" );
68 prop1[1].setName( "TEST 2" );
69 prop1[2].setName( "TEST 3" );
70 prop2[0].setName( "TEST 3" );
71 prop2[1].setName( "TEST 2" );
72 prop2[2].setName( "TEST 1" );
73 prop3[0].setName( "TEST 2" );
74 prop3[1].setName( "TEST 1" );
75 prop3[2].setName( "TEST 3" );
76 prop4[0].setName( "TEST 1" );
77 prop4[1].setName( "TEST 3" );
78
79 p1.setProperties( prop1 );
80 p2.setProperties( prop2 );
81
82 Assert.assertEquals( p1, p2 );
83 Assert.assertEquals( p1.hashCode(), p2.hashCode() );
84
85 System.out.println( p1.toString() );
86 System.out.println( p2.toString() );
87
88 final Properties clone1 = (Properties) p1.clone();
89 final Properties clone2 = (Properties) p2.clone();
90
91 Assert.assertEquals( clone1, clone2 );
92 Assert.assertEquals( clone1.hashCode(), clone2.hashCode() );
93
94 System.out.println( clone1.toString() );
95 System.out.println( clone2.toString() );
96
97 p1.setProperties( prop3 );
98
99 Assert.assertEquals( p1, p2 );
100 Assert.assertEquals( p1.hashCode(), p2.hashCode() );
101
102 p1.setProperties( prop4 );
103
104 Assert.assertFalse( p1.equals( p2 ) );
105 Assert.assertFalse( p1.hashCode() == p2.hashCode() );
106 }
107
108 public void testBackwardCompatibility_1_0() throws Exception
109 {
110 final ObjectInputStream in = new ObjectInputStream( this.getClass().
111 getResourceAsStream( "Properties.ser" ) );
112
113 final Properties current = new Properties();
114 final Properties serialized = (Properties) in.readObject();
115
116 Assert.assertEquals( current, serialized );
117 Assert.assertEquals( current.hashCode(), serialized.hashCode() );
118 }
119
120
121 }