some cleanup, re-org methods, reduce scope on some

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130976 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Rodney Waldhoff 2003-02-26 00:35:19 +00:00
parent a1dc756f64
commit fa08d185aa
1 changed files with 141 additions and 126 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestObject.java,v 1.18 2003/01/10 00:15:09 rwaldhoff Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestObject.java,v 1.19 2003/02/26 00:35:19 rwaldhoff Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -81,40 +81,29 @@ import java.io.Serializable;
* test case (method) your {@link Object} fails. * test case (method) your {@link Object} fails.
* *
* @author Rodney Waldhoff * @author Rodney Waldhoff
* @version $Revision: 1.18 $ $Date: 2003/01/10 00:15:09 $ * @author Anonymous
*
* @version $Revision: 1.19 $ $Date: 2003/02/26 00:35:19 $
*/ */
public abstract class TestObject extends BulkTest { public abstract class TestObject extends BulkTest {
// constructor
// ------------------------------------------------------------------------
public TestObject(String testName) { public TestObject(String testName) {
super(testName); super(testName);
} }
// current major release for Collections // abstract
public static final int COLLECTIONS_MAJOR_VERSION = 2; // ------------------------------------------------------------------------
/**
* Get the version of Collections that this object tries to
* maintain serialization compatibility with. Defaults to 1, the
* earliest Collections version. (Note: some collections did not
* even exist in this version).
*
* This constant makes it possible for TestMap (and other subclasses,
* if necessary) to automatically check CVS for a versionX copy of a
* Serialized object, so we can make sure that compatibility is maintained.
* See, for example, TestMap.getCanonicalFullMapName(Map map).
* Subclasses can override this variable, indicating compatibility
* with earlier Collections versions.
*
* @return The version, or <code>null</code> if this object shouldn't be
* tested for compatibility with previous versions.
*/
public String getCompatibilityVersion() {
return "1";
}
/** /**
* Return a new, empty {@link Object} to used for testing. * Return a new, empty {@link Object} to used for testing.
*/ */
public abstract Object makeObject(); protected abstract Object makeObject();
// tests
// ------------------------------------------------------------------------
public void testObjectEqualsSelf() { public void testObjectEqualsSelf() {
Object obj = makeObject(); Object obj = makeObject();
@ -158,10 +147,121 @@ public abstract class TestObject extends BulkTest {
} }
} }
private void writeExternalFormToStream(Serializable o, OutputStream stream) /**
throws IOException { * Sanity check method, makes sure that any Serializable
ObjectOutputStream oStream = new ObjectOutputStream(stream); * class can be serialized and de-serialized in memory,
oStream.writeObject(o); * using the handy makeObject() method
*
* @exception IOException
* @exception ClassNotFoundException
*/
public void testSimpleSerialization() throws IOException, ClassNotFoundException {
Object o = makeObject();
if (o instanceof Serializable) {
byte[] objekt = writeExternalFormToBytes((Serializable) o);
Object p = readExternalFormFromBytes(objekt);
}
}
/**
* If the test object is serializable, confirm that
* a canonical form exists in CVS
*
*/
public void testCanonicalEmptyCollectionExists() {
if(supportsEmptyCollections()) {
Object object = makeObject();
if(object instanceof Serializable) {
String name = getCanonicalEmptyCollectionName(object);
assertTrue("Canonical empty collection (" + name + ") is not in CVS",
new File(name).exists());
}
}
}
/**
* If the test object is serializable, confirm that
* a canonical form exists in CVS
*
*/
public void testCanonicalFullCollectionExists() {
if(supportsFullCollections()) {
Object object = makeObject();
if(object instanceof Serializable) {
String name = getCanonicalFullCollectionName(object);
assertTrue("Canonical full collection (" + name + ") is not in CVS",
new File(name).exists());
}
}
}
// protected
// ------------------------------------------------------------------------
/**
* Get the version of Collections that this object tries to
* maintain serialization compatibility with. Defaults to 1, the
* earliest Collections version. (Note: some collections did not
* even exist in this version).
*
* This constant makes it possible for TestMap (and other subclasses,
* if necessary) to automatically check CVS for a versionX copy of a
* Serialized object, so we can make sure that compatibility is maintained.
* See, for example, TestMap.getCanonicalFullMapName(Map map).
* Subclasses can override this variable, indicating compatibility
* with earlier Collections versions.
*
* @return The version, or <code>null</code> if this object shouldn't be
* tested for compatibility with previous versions.
*/
protected String getCompatibilityVersion() {
return "1";
}
/**
* Override this method if a subclass is testing a
* Collections that cannot serialize an "empty" Collection
* (e.g. Comparators have no contents)
*
* @return true
*/
protected boolean supportsEmptyCollections() {
return true;
}
/**
* Override this method if a subclass is testing a
* Collections that cannot serialize a "full" Collection
* (e.g. Comparators have no contents)
*
* @return true
*/
protected boolean supportsFullCollections() {
return true;
}
protected String getCanonicalEmptyCollectionName(Object object) {
StringBuffer retval = new StringBuffer();
retval.append("data/test/");
String colName = object.getClass().getName();
colName = colName.substring(colName.lastIndexOf(".")+1,colName.length());
retval.append(colName);
retval.append(".emptyCollection.version");
retval.append(getCompatibilityVersion());
retval.append(".obj");
return retval.toString();
}
protected String getCanonicalFullCollectionName(Object object) {
StringBuffer retval = new StringBuffer();
retval.append("data/test/");
String colName = object.getClass().getName();
colName = colName.substring(colName.lastIndexOf(".")+1,colName.length());
retval.append(colName);
retval.append(".fullCollection.version");
retval.append(getCompatibilityVersion());
retval.append(".obj");
return retval.toString();
} }
/** /**
@ -234,104 +334,19 @@ public abstract class TestObject extends BulkTest {
return readExternalFormFromStream(stream); return readExternalFormFromStream(stream);
} }
/** // private
* Sanity check method, makes sure that any Serializable // ------------------------------------------------------------------------
* class can be serialized and de-serialized in memory,
* using the handy makeObject() method private void writeExternalFormToStream(Serializable o, OutputStream stream)
* throws IOException {
* @exception IOException ObjectOutputStream oStream = new ObjectOutputStream(stream);
* @exception ClassNotFoundException oStream.writeObject(o);
*/
public void testSimpleSerialization()
throws IOException, ClassNotFoundException {
Object o = makeObject();
if (o instanceof Serializable) {
byte[] objekt = writeExternalFormToBytes((Serializable) o);
Object p = readExternalFormFromBytes(objekt);
}
} }
public String getCanonicalEmptyCollectionName(Object object) { // attributes
StringBuffer retval = new StringBuffer(); // ------------------------------------------------------------------------
retval.append("data/test/");
String colName = object.getClass().getName();
colName = colName.substring(colName.lastIndexOf(".")+1,colName.length());
retval.append(colName);
retval.append(".emptyCollection.version");
retval.append(getCompatibilityVersion());
retval.append(".obj");
return retval.toString();
}
public String getCanonicalFullCollectionName(Object object) { // current major release for Collections
StringBuffer retval = new StringBuffer(); public static final int COLLECTIONS_MAJOR_VERSION = 2;
retval.append("data/test/");
String colName = object.getClass().getName();
colName = colName.substring(colName.lastIndexOf(".")+1,colName.length());
retval.append(colName);
retval.append(".fullCollection.version");
retval.append(getCompatibilityVersion());
retval.append(".obj");
return retval.toString();
}
/**
* Override this method if a subclass is testing a
* Collections that cannot serialize an "empty" Collection
* (e.g. Comparators have no contents)
*
* @return true
*/
public boolean supportsEmptyCollections() {
return true;
}
/**
* Override this method if a subclass is testing a
* Collections that cannot serialize a "full" Collection
* (e.g. Comparators have no contents)
*
* @return true
*/
public boolean supportsFullCollections() {
return true;
}
/**
* If the test object is serializable, confirm that
* a canonical form exists in CVS
*
*/
public void testCanonicalEmptyCollectionExists() {
if (!supportsEmptyCollections()) {
return;
}
Object object = makeObject();
if (!(object instanceof Serializable)) {
return;
}
String name = getCanonicalEmptyCollectionName(object);
assertTrue("Canonical empty collection (" + name + ") is not in CVS",
new File(name).exists());
}
/**
* If the test object is serializable, confirm that
* a canonical form exists in CVS
*
*/
public void testCanonicalFullCollectionExists() {
if (!supportsFullCollections()) {
return;
}
Object object = makeObject();
if (!(object instanceof Serializable)) {
return;
}
String name = getCanonicalFullCollectionName(object);
assertTrue("Canonical full collection (" + name + ") is not in CVS",
new File(name).exists());
}
} }