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.Dependencies;
027import org.jdtaus.core.container.Dependency;
028
029/**
030 * jUnit tests for {@code Dependencies} implementations.
031 *
032 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
033 * @version $JDTAUS: DependenciesTest.java 8641 2012-09-27 06:45:17Z schulte $
034 */
035public class DependenciesTest extends TestCase
036{
037    //--DependenciesTest--------------------------------------------------------
038
039    public void testObject() throws Exception
040    {
041        final Dependencies d1 = new Dependencies();
042        final Dependencies d2 = new Dependencies();
043
044        Assert.assertEquals( d1, d2 );
045        Assert.assertEquals( d1.hashCode(), d2.hashCode() );
046
047        System.out.println( d1.toString() );
048        System.out.println( d2.toString() );
049
050        final Dependency[] deps1 =
051        {
052            new Dependency(), new Dependency(), new Dependency()
053        };
054        final Dependency[] deps2 =
055        {
056            new Dependency(), new Dependency(), new Dependency()
057        };
058        final Dependency[] deps3 =
059        {
060            new Dependency(), new Dependency(), new Dependency()
061        };
062        final Dependency[] deps4 =
063        {
064            new Dependency(), new Dependency()
065        };
066
067        deps1[0].setName( "TEST 1" );
068        deps1[1].setName( "TEST 2" );
069        deps1[2].setName( "TEST 3" );
070        deps2[0].setName( "TEST 3" );
071        deps2[1].setName( "TEST 2" );
072        deps2[2].setName( "TEST 1" );
073        deps3[0].setName( "TEST 2" );
074        deps3[1].setName( "TEST 1" );
075        deps3[2].setName( "TEST 3" );
076        deps4[0].setName( "TEST 1" );
077        deps4[1].setName( "TEST 3" );
078
079        d1.setDependencies( deps1 );
080        d2.setDependencies( deps2 );
081
082        Assert.assertEquals( d1, d2 );
083        Assert.assertEquals( d1.hashCode(), d2.hashCode() );
084
085        System.out.println( d1.toString() );
086        System.out.println( d2.toString() );
087
088        final Dependencies clone1 = (Dependencies) d1.clone();
089        final Dependencies clone2 = (Dependencies) d2.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        d1.setDependencies( deps3 );
098
099        Assert.assertEquals( d1, d2 );
100        Assert.assertEquals( d1.hashCode(), d2.hashCode() );
101
102        d1.setDependencies( deps4 );
103
104        Assert.assertFalse( d1.equals( d2 ) );
105        Assert.assertFalse( d1.hashCode() == d2.hashCode() );
106    }
107
108    public void testBackwardCompatibility_1_0() throws Exception
109    {
110        final ObjectInputStream in = new ObjectInputStream( this.getClass().
111            getResourceAsStream( "Dependencies.ser" ) );
112
113        final Dependencies current = new Dependencies();
114        final Dependencies serialized = (Dependencies) in.readObject();
115
116        Assert.assertEquals( current, serialized );
117        Assert.assertEquals( current.hashCode(), serialized.hashCode() );
118    }
119
120    //--------------------------------------------------------DependenciesTest--
121}