canonical forms for serialized maps in Collections 2.0

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130567 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Morgan James Delagrange 2002-02-22 22:01:48 +00:00
parent eaf794f2cb
commit dd7f71e66d
10 changed files with 90 additions and 10 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/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/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/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 @@ import java.util.Map;
/**
* @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
{
@ -114,4 +114,21 @@ public class TestHashMap extends TestMap
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() {
}
}

View File

@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/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/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/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 @@ import java.util.NoSuchElementException;
*
* @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>
@ -929,6 +929,69 @@ public abstract class TestMap extends TestObject {
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
public void testMapClear() {