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