View Javadoc

1   /*
2    *  jDTAUS Core API
3    *  Copyright (C) 2005 Christian Schulte
4    *  <cs@schulte.it>
5    *
6    *  This library is free software; you can redistribute it and/or
7    *  modify it under the terms of the GNU Lesser General Public
8    *  License as published by the Free Software Foundation; either
9    *  version 2.1 of the License, or any later version.
10   *
11   *  This library is distributed in the hope that it will be useful,
12   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   *  Lesser General Public License for more details.
15   *
16   *  You should have received a copy of the GNU Lesser General Public
17   *  License along with this library; if not, write to the Free Software
18   *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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.Module;
27  import org.jdtaus.core.container.Modules;
28  
29  /**
30   * jUnit tests for {@code Modules} implementations.
31   *
32   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
33   * @version $JDTAUS: ModulesTest.java 8641 2012-09-27 06:45:17Z schulte $
34   */
35  public class ModulesTest extends TestCase
36  {
37      //--ModulesTest-------------------------------------------------------------
38  
39      public void testObject() throws Exception
40      {
41          final Modules m1 = new Modules();
42          final Modules m2 = new Modules();
43  
44          Assert.assertEquals( m1, m2 );
45          Assert.assertEquals( m1.hashCode(), m2.hashCode() );
46  
47          System.out.println( m1.toString() );
48          System.out.println( m2.toString() );
49  
50          final Module[] mod1 =
51          {
52              new Module(), new Module(), new Module()
53          };
54          final Module[] mod2 =
55          {
56              new Module(), new Module(), new Module()
57          };
58          final Module[] mod3 =
59          {
60              new Module(), new Module(), new Module()
61          };
62          final Module[] mod4 =
63          {
64              new Module(), new Module()
65          };
66  
67          mod1[0].setName( "TEST 1" );
68          mod1[1].setName( "TEST 2" );
69          mod1[2].setName( "TEST 3" );
70          mod2[0].setName( "TEST 3" );
71          mod2[1].setName( "TEST 2" );
72          mod2[2].setName( "TEST 1" );
73          mod3[0].setName( "TEST 2" );
74          mod3[1].setName( "TEST 1" );
75          mod3[2].setName( "TEST 3" );
76          mod4[0].setName( "TEST 1" );
77          mod4[1].setName( "TEST 3" );
78  
79          m1.setModules( mod1 );
80          m2.setModules( mod2 );
81  
82          Assert.assertEquals( m1, m2 );
83          Assert.assertEquals( m1.hashCode(), m2.hashCode() );
84  
85          System.out.println( m1.toString() );
86          System.out.println( m2.toString() );
87  
88          final Modules clone1 = (Modules) m1.clone();
89          final Modules clone2 = (Modules) m2.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          m1.setModules( mod3 );
98  
99          Assert.assertEquals( m1, m2 );
100         Assert.assertEquals( m1.hashCode(), m2.hashCode() );
101 
102         m1.setModules( mod4 );
103 
104         Assert.assertFalse( m1.equals( m2 ) );
105         Assert.assertFalse( m1.hashCode() == m2.hashCode() );
106     }
107 
108     public void testBackwardCompatibility_1_0() throws Exception
109     {
110         final ObjectInputStream in = new ObjectInputStream( this.getClass().
111             getResourceAsStream( "Modules.ser" ) );
112 
113         final Modules current = new Modules();
114         final Modules serialized = (Modules) in.readObject();
115 
116         Assert.assertEquals( current, serialized );
117         Assert.assertEquals( current.hashCode(), serialized.hashCode() );
118     }
119 
120     //-------------------------------------------------------------ModulesTest--
121 }