commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1051248 - in /commons/proper/collections/trunk/src: java/org/apache/commons/collections/splitmap/AbstractIterableGetMapDecorator.java test/org/apache/commons/collections/splitmap/TestTransformedMap.java
Date Mon, 20 Dec 2010 19:24:29 GMT
Author: sebb
Date: Mon Dec 20 19:24:29 2010
New Revision: 1051248

URL: http://svn.apache.org/viewvc?rev=1051248&view=rev
Log:
COLLECTIONS-363 TransformedMap is Serializable but its superclass doesn't define an accessible
void constructor

Modified:
    commons/proper/collections/trunk/src/java/org/apache/commons/collections/splitmap/AbstractIterableGetMapDecorator.java
    commons/proper/collections/trunk/src/test/org/apache/commons/collections/splitmap/TestTransformedMap.java

Modified: commons/proper/collections/trunk/src/java/org/apache/commons/collections/splitmap/AbstractIterableGetMapDecorator.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/java/org/apache/commons/collections/splitmap/AbstractIterableGetMapDecorator.java?rev=1051248&r1=1051247&r2=1051248&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/java/org/apache/commons/collections/splitmap/AbstractIterableGetMapDecorator.java
(original)
+++ commons/proper/collections/trunk/src/java/org/apache/commons/collections/splitmap/AbstractIterableGetMapDecorator.java
Mon Dec 20 19:24:29 2010
@@ -48,6 +48,13 @@ public class AbstractIterableGetMapDecor
     }
 
     /**
+     * Constructor only used in deserialization, do not use otherwise.
+     */
+    protected AbstractIterableGetMapDecorator() {
+        super();
+    }
+
+    /**
      * Gets the map being decorated.
      *
      * @return the decorated map

Modified: commons/proper/collections/trunk/src/test/org/apache/commons/collections/splitmap/TestTransformedMap.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/org/apache/commons/collections/splitmap/TestTransformedMap.java?rev=1051248&r1=1051247&r2=1051248&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/org/apache/commons/collections/splitmap/TestTransformedMap.java
(original)
+++ commons/proper/collections/trunk/src/test/org/apache/commons/collections/splitmap/TestTransformedMap.java
Mon Dec 20 19:24:29 2010
@@ -16,10 +16,7 @@
  */
 package org.apache.commons.collections.splitmap;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.*;
 import java.math.BigInteger;
 import java.util.HashMap;
 
@@ -123,20 +120,57 @@ public class TestTransformedMap extends 
         }
     }
 
-    public void TODOtestCollections363() throws Exception {
+    public void testEmptyMap() throws IOException, ClassNotFoundException {
         TransformedMap<String, String, String, String> map = TransformedMap.decorate(
-                new HashMap<String, String>(), 
-                NOPTransformer.<String> getInstance(), 
-                NOPTransformer.<String> getInstance());
-        
-        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
-        ObjectOutputStream out = new ObjectOutputStream(bytes);
-        out.writeObject(map);
-        out.close();
-        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
+                new HashMap<String, String>(),
+                NOPTransformer.<String>getInstance(),
+                NOPTransformer.<String>getInstance() );
+
+        ObjectInputStream in = new ObjectInputStream( new FileInputStream( "data/test/TransformedMap.emptyCollection.version3.2.obj"
) );
         Object readObject = in.readObject();
         in.close();
-        assertEquals("deserializing class: " + map.getClass().getName(), map.getClass(),
readObject
-                .getClass());
+
+        TransformedMap<?, ?, ?, ?> readMap = (TransformedMap<?, ?, ?, ?>) readObject;
+        assertTrue( "Map should be empty", readMap.size() == 0 );
+        assertEquals( map.entrySet(), readMap.entrySet() );
+    }
+
+    public void testFullMap() throws IOException, ClassNotFoundException {
+        TransformedMap<String, String, String, String> map = TransformedMap.decorate(
+                new HashMap<String, String>(),
+                NOPTransformer.<String>getInstance(),
+                NOPTransformer.<String>getInstance() );
+        map.put( "a", "b" );
+        map.put( "c", "d" );
+        map.put( "e", "f" );
+        map.put( "g", "h" );
+
+        ObjectInputStream in = new ObjectInputStream( new FileInputStream( "data/test/TransformedMap.fullCollection.version3.2.obj"
) );
+        Object readObject = in.readObject();
+        in.close();
+
+        TransformedMap<?, ?, ?, ?> readMap = (TransformedMap<?, ?, ?, ?>) readObject;
+        assertFalse( "Map should not be empty", readMap.size() == 0 );
+        assertEquals( map.entrySet(), readMap.entrySet() );
     }
+//
+//    public void testCreate() throws IOException {
+//        TransformedMap<String, String, String, String> map = TransformedMap.decorate(
+//                new HashMap<String, String>(),
+//                NOPTransformer.<String>getInstance(),
+//                NOPTransformer.<String>getInstance() );
+//
+//        ObjectOutputStream out = new ObjectOutputStream(
+//                new FileOutputStream( "data/test/TransformedMap.emptyCollection.version3.2.obj"
) );
+//        out.writeObject( map );
+//
+//        map.put( "a", "b" );
+//        map.put( "c", "d" );
+//        map.put( "e", "f" );
+//        map.put( "g", "h" );
+//
+//        out = new ObjectOutputStream(
+//                new FileOutputStream( "data/test/TransformedMap.fullCollection.version3.2.obj"
) );
+//        out.writeObject( map );
+//    }
 }



Mime
View raw message