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