001/*
002 *  jDTAUS Core API
003 *  Copyright (C) 2005 Christian Schulte
004 *  <cs@schulte.it>
005 *
006 *  This library is free software; you can redistribute it and/or
007 *  modify it under the terms of the GNU Lesser General Public
008 *  License as published by the Free Software Foundation; either
009 *  version 2.1 of the License, or any later version.
010 *
011 *  This library is distributed in the hope that it will be useful,
012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 *  Lesser General Public License for more details.
015 *
016 *  You should have received a copy of the GNU Lesser General Public
017 *  License along with this library; if not, write to the Free Software
018 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
019 *
020 */
021package org.jdtaus.core.container.test;
022
023import java.io.ObjectInputStream;
024import junit.framework.Assert;
025import junit.framework.TestCase;
026import org.jdtaus.core.container.Implementation;
027import org.jdtaus.core.container.Implementations;
028
029/**
030 * jUnit tests for {@code Implementations} implementations.
031 *
032 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
033 * @version $JDTAUS: ImplementationsTest.java 8641 2012-09-27 06:45:17Z schulte $
034 */
035public class ImplementationsTest extends TestCase
036{
037    //--ImplementationsTest-----------------------------------------------------
038
039    public void testObject() throws Exception
040    {
041        final Implementations i1 = new Implementations();
042        final Implementations i2 = new Implementations();
043
044        Assert.assertEquals( i1, i2 );
045        Assert.assertEquals( i1.hashCode(), i2.hashCode() );
046
047        System.out.println( i1.toString() );
048        System.out.println( i2.toString() );
049
050        final Implementation[] impl1 =
051        {
052            new Implementation(), new Implementation(), new Implementation()
053        };
054        final Implementation[] impl2 =
055        {
056            new Implementation(), new Implementation(), new Implementation()
057        };
058        final Implementation[] impl3 =
059        {
060            new Implementation(), new Implementation(), new Implementation()
061        };
062        final Implementation[] impl4 =
063        {
064            new Implementation(), new Implementation()
065        };
066
067        impl1[0].setIdentifier( "TEST 1" );
068        impl1[1].setIdentifier( "TEST 2" );
069        impl1[2].setIdentifier( "TEST 3" );
070        impl2[0].setIdentifier( "TEST 3" );
071        impl2[1].setIdentifier( "TEST 2" );
072        impl2[2].setIdentifier( "TEST 1" );
073        impl3[0].setIdentifier( "TEST 2" );
074        impl3[1].setIdentifier( "TEST 1" );
075        impl3[2].setIdentifier( "TEST 3" );
076        impl4[0].setIdentifier( "TEST 1" );
077        impl4[1].setIdentifier( "TEST 3" );
078
079        i1.setImplementations( impl1 );
080        i2.setImplementations( impl2 );
081
082        Assert.assertEquals( i1, i2 );
083        Assert.assertEquals( i1.hashCode(), i2.hashCode() );
084
085        System.out.println( i1.toString() );
086        System.out.println( i2.toString() );
087
088        final Implementations clone1 = (Implementations) i1.clone();
089        final Implementations clone2 = (Implementations) i2.clone();
090
091        Assert.assertEquals( clone1, clone2 );
092        Assert.assertEquals( clone1.hashCode(), clone2.hashCode() );
093
094        System.out.println( clone1.toString() );
095        System.out.println( clone2.toString() );
096
097        i1.setImplementations( impl3 );
098
099        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    //-----------------------------------------------------ImplementationsTest--
121}