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.Dependencies;
27  import org.jdtaus.core.container.Implementation;
28  import org.jdtaus.core.container.Properties;
29  import org.jdtaus.core.container.Specifications;
30  
31  /**
32   * jUnit tests for {@code Implementation} implementations.
33   *
34   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
35   * @version $JDTAUS: ImplementationTest.java 8641 2012-09-27 06:45:17Z schulte $
36   */
37  public class ImplementationTest extends TestCase
38  {
39      //--ImplementationTest------------------------------------------------------
40  
41      public void testObject() throws Exception
42      {
43          final Implementation i1 = new Implementation();
44          final Implementation i2 = new Implementation();
45  
46          Assert.assertEquals( i1, i2 );
47          Assert.assertEquals( i1.hashCode(), i2.hashCode() );
48  
49          System.out.println( i1.toString() );
50          System.out.println( i2.toString() );
51  
52          i1.setDependencies( new Dependencies() );
53          i1.setImplementedSpecifications( new Specifications() );
54          i1.setParent( new Implementation() );
55          i1.setProperties( new Properties() );
56  
57          i2.setDependencies( new Dependencies() );
58          i2.setImplementedSpecifications( new Specifications() );
59          i2.setParent( new Implementation() );
60          i2.setProperties( new Properties() );
61  
62          Assert.assertEquals( i1, i2 );
63          Assert.assertEquals( i1.hashCode(), i2.hashCode() );
64  
65          System.out.println( i1.toString() );
66          System.out.println( i2.toString() );
67  
68          final Implementation clone1 = (Implementation) i1.clone();
69          final Implementation clone2 = (Implementation) i2.clone();
70  
71          Assert.assertEquals( clone1, clone2 );
72          Assert.assertEquals( clone1.hashCode(), clone2.hashCode() );
73  
74          System.out.println( clone1.toString() );
75          System.out.println( clone2.toString() );
76      }
77  
78      public void testBackwardCompatibility_1_0() throws Exception
79      {
80          final ObjectInputStream in = new ObjectInputStream( this.getClass().
81              getResourceAsStream( "Implementation.ser" ) );
82  
83          final Implementation current = new Implementation();
84          final Implementation serialized = (Implementation) in.readObject();
85  
86          Assert.assertEquals( current, serialized );
87          Assert.assertEquals( current.hashCode(), serialized.hashCode() );
88      }
89  
90      //------------------------------------------------------ImplementationTest--
91  }