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