You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by mo...@apache.org on 2002/02/22 23:01:48 UTC

cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestHashMap.java TestMap.java

morgand     02/02/22 14:01:48

  Modified:    collections/src/test/org/apache/commons/collections
                        TestHashMap.java TestMap.java
  Log:
  canonical forms for serialized maps in Collections 2.0
  
  Revision  Changes    Path
  1.4       +21 -4     jakarta-commons/collections/src/test/org/apache/commons/collections/TestHashMap.java
  
  Index: TestHashMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestHashMap.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestHashMap.java	22 Feb 2002 02:18:50 -0000	1.3
  +++ TestHashMap.java	22 Feb 2002 22:01:48 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestHashMap.java,v 1.3 2002/02/22 02:18:50 mas Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/02/22 02:18:50 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestHashMap.java,v 1.4 2002/02/22 22:01:48 morgand Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/02/22 22:01:48 $
    *
    * ====================================================================
    *
  @@ -69,7 +69,7 @@
   
   /**
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: TestHashMap.java,v 1.3 2002/02/22 02:18:50 mas Exp $
  + * @version $Id: TestHashMap.java,v 1.4 2002/02/22 22:01:48 morgand Exp $
    */
   public class TestHashMap extends TestMap
   {
  @@ -113,5 +113,22 @@
           map.put("second", "Second Item");
           assertEquals("Top item is 'Second Item'", map.get("first"), "First Item");
           assertEquals("Next Item is 'First Item'", map.get("second"), "Second Item");
  +    }
  +
  +
  +    /**
  +     * We don't need to test compatibility for JVM collections.  Override in 
  +     * subclasses.
  +     */
  +    public void testEmptyMapCompatibility() {
  +
  +    }
  +
  +    /**
  +     * We don't need to test compatibility for JVM collections.  Override in 
  +     * subclasses.
  +     */
  +    public void testFullMapCompatibility() {
  +
       }
   }
  
  
  
  1.10      +69 -6     jakarta-commons/collections/src/test/org/apache/commons/collections/TestMap.java
  
  Index: TestMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestMap.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestMap.java	22 Feb 2002 06:16:35 -0000	1.9
  +++ TestMap.java	22 Feb 2002 22:01:48 -0000	1.10
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestMap.java,v 1.9 2002/02/22 06:16:35 morgand Exp $
  - * $Revision: 1.9 $
  - * $Date: 2002/02/22 06:16:35 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestMap.java,v 1.10 2002/02/22 22:01:48 morgand Exp $
  + * $Revision: 1.10 $
  + * $Date: 2002/02/22 22:01:48 $
    *
    * ====================================================================
    *
  @@ -87,13 +87,13 @@
    *
    * @author Michael Smith
    * @author Rodney Waldhoff
  - * @version $Id: TestMap.java,v 1.9 2002/02/22 06:16:35 morgand Exp $
  + * @version $Id: TestMap.java,v 1.10 2002/02/22 22:01:48 morgand Exp $
    */
   public abstract class TestMap extends TestObject {
  +
       public TestMap(String testName) {
           super(testName);
       }
  -
       /**
        *  Override if your map does not allow a <code>null</code> key.  The
        *  default implementation returns <code>true</code>
  @@ -927,7 +927,70 @@
   
           assertEquals("Both maps are same size",map.size(), getSampleKeys().length);
           assertEquals("Both maps are same size",map2.size(),getSampleKeys().length);
  -    } 
  +    }
  +
  +
  +    public String getCanonicalEmptyMapName(Map map) {
  +        StringBuffer retval = new StringBuffer();
  +        retval.append("data/test/");
  +        String mapName = map.getClass().getName();
  +        mapName = mapName.substring(mapName.lastIndexOf(".")+1,mapName.length());
  +        retval.append(mapName);
  +        retval.append(".emptyMap.");
  +        retval.append(COLLECTIONS_VERSION);
  +        retval.append(".obj");
  +        return retval.toString();
  +    }
  +
  +    public String getCanonicalFullMapName(Map map) {
  +        StringBuffer retval = new StringBuffer();
  +        retval.append("data/test/");
  +        String mapName = map.getClass().getName();
  +        mapName = mapName.substring(mapName.lastIndexOf(".")+1,mapName.length());
  +        retval.append(mapName);
  +        retval.append(".fullMap.");
  +        retval.append(COLLECTIONS_VERSION);
  +        retval.append(".obj");
  +        return retval.toString();
  +    }
  +
  +    /**
  +     * Compare the current serialized form of the Map
  +     * against the canonical version in CVS.
  +     */
  +    public void testEmptyMapCompatibility() throws IOException, ClassNotFoundException {
  +        /**
  +         * Create canonical objects with this code
  +        Map map = makeEmptyMap();
  +        if (!(map instanceof Serializable)) return;
  +        
  +        writeExternalFormToDisk((Serializable) map, getCanonicalEmptyMapName(map));
  +        */
  +
  +        // test to make sure the canonical form has been preserved
  +        if (!(makeEmptyMap() instanceof Serializable)) return;
  +        Map map = (Map) readExternalFormFromDisk(getCanonicalEmptyMapName(makeEmptyMap()));
  +        assertTrue("Maps is empty",map.isEmpty()  == true);
  +    }
  +
  +        /**
  +     * Compare the current serialized form of the Map
  +     * against the canonical version in CVS.
  +     */
  +    public void testFullMapCompatibility() throws IOException, ClassNotFoundException {
  +        /**
  +         * Create canonical objects with this code
  +        Map map = makeFullMap();
  +        if (!(map instanceof Serializable)) return;
  +        
  +        writeExternalFormToDisk((Serializable) map, getCanonicalFullMapName(map));
  +        */
  +
  +        // test to make sure the canonical form has been preserved
  +        if (!(makeFullMap() instanceof Serializable)) return;
  +        Map map = (Map) readExternalFormFromDisk(getCanonicalFullMapName(makeFullMap()));
  +        assertEquals("Both maps are same size",map.size(), getSampleKeys().length);
  +    }
   
       /*
           // optional operation
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>