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