commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r637495 - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/buffer/ test/org/apache/commons/collections/ test/org/apache/commons/collections/buffer/
Date Sun, 16 Mar 2008 00:26:56 GMT
Author: bayard
Date: Sat Mar 15 17:26:44 2008
New Revision: 637495

URL: http://svn.apache.org/viewvc?rev=637495&view=rev
Log:
Applying a unit test for COLLECTIONS-220. AbstractTestObject is refactored to provide a utility
method that serializes and then deserializes. Dave Meikle's fix for said unit test is also
applied. 

Modified:
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/AbstractTestObject.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java?rev=637495&r1=637494&r2=637495&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java
(original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java
Sat Mar 15 17:26:44 2008
@@ -115,6 +115,7 @@
     private void writeObject(ObjectOutputStream out) throws IOException {
         out.defaultWriteObject();
         out.writeInt(size());
+        out.writeInt(buffer.length);
         for (Iterator it = iterator(); it.hasNext();) {
             out.writeObject(it.next());
         }
@@ -130,7 +131,8 @@
     private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
         in.defaultReadObject();
         int size = in.readInt();
-        buffer = new Object[size + 1];
+        int length = in.readInt();
+        buffer = new Object[length];
         for (int i = 0; i < size; i++) {
             buffer[i] = in.readObject();
         }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/AbstractTestObject.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/AbstractTestObject.java?rev=637495&r1=637494&r2=637495&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/AbstractTestObject.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/AbstractTestObject.java
Sat Mar 15 17:26:44 2008
@@ -138,17 +138,23 @@
         }
     }
 
+    protected Object serializeDeserialize(Object obj) throws Exception {
+        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();
+
+        return dest;
+    }
+
     public void testSerializeDeserializeThenCompare() throws Exception {
         Object obj = makeObject();
         if (obj instanceof Serializable && isTestSerialization()) {
-            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();
+            Object dest = serializeDeserialize(obj);
             if (isEqualsCheckable()) {
                 assertEquals("obj != deserialize(serialize(obj))", obj, dest);
             }

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java?rev=637495&r1=637494&r2=637495&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/buffer/TestUnboundedFifoBuffer.java
Sat Mar 15 17:26:44 2008
@@ -413,6 +413,17 @@
     }
 
     //-----------------------------------------------------------------------
+    public void testCollections220() throws Exception {
+         UnboundedFifoBuffer buffer = new UnboundedFifoBuffer();
+         
+         buffer = (UnboundedFifoBuffer) serializeDeserialize(buffer);
+
+         // test size() gets incremented
+         buffer.add("Foo");
+         assertEquals(1, buffer.size());
+    }
+
+    //-----------------------------------------------------------------------
     public String getCompatibilityVersion() {
         return "3.1";
     }



Mime
View raw message