From a61511a01ba848dd5505604a8ecc2c9d57ae5235 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Fri, 9 Apr 2004 15:16:24 +0000 Subject: [PATCH] Increase testing of serialization git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131646 13f79535-47bb-0310-9956-ffa450edef68 --- .../collection/AbstractTestCollection.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/test/org/apache/commons/collections/collection/AbstractTestCollection.java b/src/test/org/apache/commons/collections/collection/AbstractTestCollection.java index 4fa5d1b1c..4087339b8 100644 --- a/src/test/org/apache/commons/collections/collection/AbstractTestCollection.java +++ b/src/test/org/apache/commons/collections/collection/AbstractTestCollection.java @@ -15,6 +15,11 @@ */ package org.apache.commons.collections.collection; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; @@ -107,7 +112,7 @@ import org.apache.commons.collections.AbstractTestObject; * you may still use this base set of cases. Simply override the * test case (method) your {@link Collection} fails. * - * @version $Revision: 1.4 $ $Date: 2004/02/18 01:20:40 $ + * @version $Revision: 1.5 $ $Date: 2004/04/09 15:16:24 $ * * @author Rodney Waldhoff * @author Paul Jack @@ -1285,4 +1290,30 @@ public abstract class AbstractTestCollection extends AbstractTestObject { } } + public void testSerializeDeserializeThenCompare() throws Exception { + Object obj = makeCollection(); + if (obj instanceof Serializable) { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(buffer); + out.writeObject(obj); + out.close(); + + ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); + Object dest = in.readObject(); + in.close(); + assertEquals("obj != deserialize(serialize(obj)) - EMPTY Collection", obj, dest); + } + obj = makeFullCollection(); + if (obj instanceof Serializable) { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(buffer); + out.writeObject(obj); + out.close(); + + ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); + Object dest = in.readObject(); + in.close(); + assertEquals("obj != deserialize(serialize(obj)) - FULL Collection", obj, dest); + } + } }