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