Author: joehni
Date: Mon Jan 23 12:35:37 2006
New Revision: 371656

URL: http://svn.apache.org/viewcvs?rev=371656&view=rev
Log:
Ensure unchanged binary representation.

Modified:
    
jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/test/AssertSerialization.java

Modified: 
jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/test/AssertSerialization.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/test/AssertSerialization.java?rev=371656&r1=371655&r2=371656&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/test/AssertSerialization.java
 (original)
+++ 
jakarta/commons/sandbox/id/trunk/src/test/org/apache/commons/id/test/AssertSerialization.java
 Mon Jan 23 12:35:37 2006
@@ -28,6 +28,7 @@
 import java.io.FileOutputStream;
 import java.io.FilenameFilter;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InvalidClassException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
@@ -260,6 +261,34 @@
         }
 
         /**
+         * Ensure that serialized reference is still the same.
+         * 
+         * @throws IOException
+         * @since 1.0
+         */
+        public void testBinaryRepresentationIsStillValid() throws IOException {
+            final Class type = context.getType();
+            final ObjectStreamClass osc = ObjectStreamClass.lookup(type);
+            final Serializable reference = context.createReference();
+            assertNotNull("No reference object for " + type.getName() + " 
retrieved", reference);
+            assertSerializable(baos, "", reference, type);
+            final File referenceDir = context.getReferenceBaseDir();
+            final File referenceFile = new File(new File(referenceDir, 
osc.getName()), Long
+                    .toString(osc.getSerialVersionUID())
+                    + ".ser");
+            final InputStream expected = new FileInputStream(referenceFile);
+            try {
+                AssertIO.assertInputStreamEquals(
+                        "Serialization of "
+                                + type.getName()
+                                + " has changed regarding the reference", 
expected,
+                        new ByteArrayInputStream(baos.toByteArray()));
+            } finally {
+                expected.close();
+            }
+        }
+
+        /**
          * Test the compatibility with a version of the type.
          * 
          * @param filename the filename of the file with the serialized object
@@ -325,6 +354,7 @@
     public static TestSuite createSerializationTestSuite(final Context 
context) {
         final TestSuite suite = new TestSuite("Serialization Tests");
         suite.addTest(new SerializationTest("testSerialization", context));
+        suite.addTest(new 
SerializationTest("testBinaryRepresentationIsStillValid", context));
 
         final Class type = context.getType();
         final File referenceDir = new File(context.getReferenceBaseDir(), 
type.getName());



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to