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