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.Argument;
027import org.jdtaus.core.container.Arguments;
028
029/**
030 * jUnit tests for {@code Arguments} implementations.
031 *
032 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
033 * @version $JDTAUS: ArgumentsTest.java 8641 2012-09-27 06:45:17Z schulte $
034 */
035public class ArgumentsTest extends TestCase
036{
037    //--ArgumentsTest-----------------------------------------------------------
038
039    public void testObject() throws Exception
040    {
041        final Arguments a1 = new Arguments();
042        final Arguments a2 = new Arguments();
043
044        Assert.assertEquals( a1, a2 );
045        Assert.assertEquals( a1.hashCode(), a2.hashCode() );
046
047        System.out.println( a1.toString() );
048        System.out.println( a2.toString() );
049
050        final Argument args1 = new Argument();
051        final Argument args2 = new Argument();
052        final Argument args3 = new Argument();
053
054        args1.setName( "TEST1" );
055        args2.setName( "TEST2" );
056        args3.setName( "TEST3" );
057
058        a1.setArguments( new Argument[]
059            {
060                args1, args2, args3
061            } );
062
063        a2.setArguments( new Argument[]
064            {
065                args1, args2, args3
066            } );
067
068        Assert.assertEquals( a1, a2 );
069        Assert.assertEquals( a1.hashCode(), a2.hashCode() );
070
071        System.out.println( a1.toString() );
072        System.out.println( a2.toString() );
073
074        final Arguments clone1 = (Arguments) a1.clone();
075        final Arguments clone2 = (Arguments) a2.clone();
076
077        Assert.assertEquals( clone1, clone2 );
078        Assert.assertEquals( clone1.hashCode(), clone2.hashCode() );
079
080        System.out.println( clone1.toString() );
081        System.out.println( clone2.toString() );
082    }
083
084    public void testBackwardCompatibility_1_5() throws Exception
085    {
086        final ObjectInputStream in = new ObjectInputStream( this.getClass().
087            getResourceAsStream( "Arguments.ser" ) );
088
089        final Arguments current = new Arguments();
090        final Arguments serialized = (Arguments) in.readObject();
091
092        Assert.assertEquals( current, serialized );
093        Assert.assertEquals( current.hashCode(), serialized.hashCode() );
094    }
095
096    //-----------------------------------------------------------ArgumentsTest--
097}