harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r440088 - /incubator/harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java
Date Mon, 04 Sep 2006 14:24:35 GMT
Author: smishura
Date: Mon Sep  4 07:24:34 2006
New Revision: 440088

URL: http://svn.apache.org/viewvc?view=rev&rev=440088
Log:
Add method copySerializable()

Modified:
    incubator/harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java?view=diff&rev=440088&r1=440087&r2=440088
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java
Mon Sep  4 07:24:34 2006
@@ -194,12 +194,12 @@
     /**
      * Deserializes single object from an input stream.
      */
-    public static Object getObjectFromStream(InputStream is) throws IOException,
+    public static Serializable getObjectFromStream(InputStream is) throws IOException,
         ClassNotFoundException {
         ObjectInputStream ois = new ObjectInputStream(is);
         Object result = ois.readObject();
         ois.close();
-        return result;
+        return (Serializable)result;
     }
     
     /**
@@ -460,13 +460,9 @@
     public static void verifySelf(Object object, SerializableAssert comparator)
             throws Exception {
 
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        putObjectToStream(object, out);
-        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-
-        comparator.assertDeserialized((Serializable) object,
-                (Serializable) getObjectFromStream(in));
+        Serializable initial = (Serializable) object;
 
+        comparator.assertDeserialized(initial, copySerializable(initial));
     }
 
     /**
@@ -523,7 +519,7 @@
         Assert.assertNotNull("Failed to load serialization resource file: "
                 + path, in);
 
-        return (Serializable)getObjectFromStream(in);
+        return getObjectFromStream(in);
     }
     
     /**
@@ -562,5 +558,22 @@
         // don't forget to remove it from test case after using
         Assert.fail("Generating golden file.\nGolden file name:"
                 + goldenFile.getAbsolutePath());
+    }
+    
+    /**
+     * Copies an object by serializing/deserializing it.
+     * 
+     * @param initial -
+     *            an object to be copied
+     * @return copy of provided object
+     */
+    public static Serializable copySerializable(Serializable initial)
+            throws IOException, ClassNotFoundException {
+
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        putObjectToStream(initial, out);
+        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+
+        return getObjectFromStream(in);
     }
 }



Mime
View raw message