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.Implementation;
27 import org.jdtaus.core.container.Implementations;
28
29
30
31
32
33
34
35 public class ImplementationsTest extends TestCase
36 {
37
38
39 public void testObject() throws Exception
40 {
41 final Implementations i1 = new Implementations();
42 final Implementations i2 = new Implementations();
43
44 Assert.assertEquals( i1, i2 );
45 Assert.assertEquals( i1.hashCode(), i2.hashCode() );
46
47 System.out.println( i1.toString() );
48 System.out.println( i2.toString() );
49
50 final Implementation[] impl1 =
51 {
52 new Implementation(), new Implementation(), new Implementation()
53 };
54 final Implementation[] impl2 =
55 {
56 new Implementation(), new Implementation(), new Implementation()
57 };
58 final Implementation[] impl3 =
59 {
60 new Implementation(), new Implementation(), new Implementation()
61 };
62 final Implementation[] impl4 =
63 {
64 new Implementation(), new Implementation()
65 };
66
67 impl1[0].setIdentifier( "TEST 1" );
68 impl1[1].setIdentifier( "TEST 2" );
69 impl1[2].setIdentifier( "TEST 3" );
70 impl2[0].setIdentifier( "TEST 3" );
71 impl2[1].setIdentifier( "TEST 2" );
72 impl2[2].setIdentifier( "TEST 1" );
73 impl3[0].setIdentifier( "TEST 2" );
74 impl3[1].setIdentifier( "TEST 1" );
75 impl3[2].setIdentifier( "TEST 3" );
76 impl4[0].setIdentifier( "TEST 1" );
77 impl4[1].setIdentifier( "TEST 3" );
78
79 i1.setImplementations( impl1 );
80 i2.setImplementations( impl2 );
81
82 Assert.assertEquals( i1, i2 );
83 Assert.assertEquals( i1.hashCode(), i2.hashCode() );
84
85 System.out.println( i1.toString() );
86 System.out.println( i2.toString() );
87
88 final Implementations clone1 = (Implementations) i1.clone();
89 final Implementations clone2 = (Implementations) i2.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 i1.setImplementations( impl3 );
98
99 Assert.assertEquals( i1, i2 );
100 Assert.assertEquals( i1.hashCode(), i2.hashCode() );
101
102 i1.setImplementations( impl4 );
103
104 Assert.assertFalse( i1.equals( i2 ) );
105 Assert.assertFalse( i1.hashCode() == i2.hashCode() );
106 }
107
108 public void testBackwardCompatibility_1_0() throws Exception
109 {
110 final ObjectInputStream in = new ObjectInputStream( this.getClass().
111 getResourceAsStream( "Implementations.ser" ) );
112
113 final Implementations current = new Implementations();
114 final Implementations serialized = (Implementations) in.readObject();
115
116 Assert.assertEquals( current, serialized );
117 Assert.assertEquals( current.hashCode(), serialized.hashCode() );
118 }
119
120
121 }