Add isTestSerialization() method to block serialization tests

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131758 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2004-05-31 22:39:20 +00:00
parent 111e7b39de
commit 3f58c1e6f0
9 changed files with 72 additions and 65 deletions

View File

@ -37,7 +37,7 @@ import java.io.Serializable;
* you may still use this base set of cases. Simply override the
* test case (method) your {@link Object} fails.
*
* @version $Revision: 1.5 $ $Date: 2004/04/09 15:17:11 $
* @version $Revision: 1.6 $ $Date: 2004/05/31 22:39:20 $
*
* @author Rodney Waldhoff
* @author Stephen Colebourne
@ -87,6 +87,14 @@ public abstract class AbstractTestObject extends BulkTest {
return true;
}
/**
* Is serialization testing supported.
* Default is true.
*/
public boolean isTestSerialization() {
return true;
}
//-----------------------------------------------------------------------
public void testObjectEqualsSelf() {
Object obj = makeObject();
@ -123,7 +131,7 @@ public abstract class AbstractTestObject extends BulkTest {
public void testSerializeDeserializeThenCompare() throws Exception {
Object obj = makeObject();
if (obj instanceof Serializable) {
if (obj instanceof Serializable && isTestSerialization()) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
out.writeObject(obj);
@ -146,7 +154,7 @@ public abstract class AbstractTestObject extends BulkTest {
*/
public void testSimpleSerialization() throws Exception {
Object o = makeObject();
if (o instanceof Serializable) {
if (o instanceof Serializable && isTestSerialization()) {
byte[] objekt = writeExternalFormToBytes((Serializable) o);
Object p = readExternalFormFromBytes(objekt);
}
@ -157,7 +165,7 @@ public abstract class AbstractTestObject extends BulkTest {
* If the test object is serializable, confirm that a canonical form exists.
*/
public void testCanonicalEmptyCollectionExists() {
if (supportsEmptyCollections()) {
if (supportsEmptyCollections() && isTestSerialization() && !skipSerializedCanonicalTests()) {
Object object = makeObject();
if (object instanceof Serializable) {
String name = getCanonicalEmptyCollectionName(object);
@ -173,7 +181,7 @@ public abstract class AbstractTestObject extends BulkTest {
* If the test object is serializable, confirm that a canonical form exists.
*/
public void testCanonicalFullCollectionExists() {
if (supportsFullCollections()) {
if (supportsFullCollections() && isTestSerialization() && !skipSerializedCanonicalTests()) {
Object object = makeObject();
if (object instanceof Serializable) {
String name = getCanonicalFullCollectionName(object);

View File

@ -36,7 +36,7 @@ import org.apache.commons.collections.Bag;
* you may still use this base set of cases. Simply override the
* test case (method) your bag fails.
*
* @version $Revision: 1.8 $ $Date: 2004/02/18 01:20:39 $
* @version $Revision: 1.9 $ $Date: 2004/05/31 22:39:20 $
*
* @author Chuck Burdick
* @author Stephen Colebourne
@ -425,7 +425,7 @@ public abstract class AbstractTestBag extends AbstractTestObject {
//-----------------------------------------------------------------------
public void testEmptyBagSerialization() throws IOException, ClassNotFoundException {
Bag bag = makeBag();
if (!(bag instanceof Serializable)) return;
if (!(bag instanceof Serializable && isTestSerialization())) return;
byte[] objekt = writeExternalFormToBytes((Serializable) bag);
Bag bag2 = (Bag) readExternalFormFromBytes(objekt);
@ -442,7 +442,7 @@ public abstract class AbstractTestBag extends AbstractTestObject {
bag.add("B");
bag.add("C");
int size = bag.size();
if (!(bag instanceof Serializable)) return;
if (!(bag instanceof Serializable && isTestSerialization())) return;
byte[] objekt = writeExternalFormToBytes((Serializable) bag);
Bag bag2 = (Bag) readExternalFormFromBytes(objekt);
@ -458,7 +458,7 @@ public abstract class AbstractTestBag extends AbstractTestObject {
public void testEmptyBagCompatibility() throws IOException, ClassNotFoundException {
// test to make sure the canonical form has been preserved
Bag bag = makeBag();
if(bag instanceof Serializable && !skipSerializedCanonicalTests()) {
if(bag instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
Bag bag2 = (Bag) readExternalFormFromDisk(getCanonicalEmptyCollectionName(bag));
assertTrue("Bag is empty",bag2.size() == 0);
assertEquals(bag, bag2);
@ -477,7 +477,7 @@ public abstract class AbstractTestBag extends AbstractTestObject {
bag.add("B");
bag.add("B");
bag.add("C");
if(bag instanceof Serializable && !skipSerializedCanonicalTests()) {
if(bag instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
Bag bag2 = (Bag) readExternalFormFromDisk(getCanonicalFullCollectionName(bag));
assertEquals("Bag is the right size",bag.size(), bag2.size());
assertEquals(bag, bag2);

View File

@ -112,7 +112,7 @@ import org.apache.commons.collections.AbstractTestObject;
* you may still use this base set of cases. Simply override the
* test case (method) your {@link Collection} fails.
*
* @version $Revision: 1.6 $ $Date: 2004/05/31 19:09:14 $
* @version $Revision: 1.7 $ $Date: 2004/05/31 22:39:20 $
*
* @author Rodney Waldhoff
* @author Paul Jack
@ -1300,7 +1300,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
public void testSerializeDeserializeThenCompare() throws Exception {
Object obj = makeCollection();
if (obj instanceof Serializable) {
if (obj instanceof Serializable && isTestSerialization()) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
out.writeObject(obj);
@ -1314,7 +1314,7 @@ public abstract class AbstractTestCollection extends AbstractTestObject {
}
}
obj = makeFullCollection();
if (obj instanceof Serializable) {
if (obj instanceof Serializable && isTestSerialization()) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
out.writeObject(obj);

View File

@ -45,7 +45,7 @@ import org.apache.commons.collections.iterators.AbstractTestListIterator;
* test case (method) your {@link List} fails or override one of the
* protected methods from AbstractTestCollection.
*
* @version $Revision: 1.8 $ $Date: 2004/05/31 19:09:14 $
* @version $Revision: 1.9 $ $Date: 2004/05/31 22:39:20 $
*
* @author Rodney Waldhoff
* @author Paul Jack
@ -946,7 +946,7 @@ public abstract class AbstractTestList extends AbstractTestCollection {
public void testEmptyListSerialization()
throws IOException, ClassNotFoundException {
List list = makeEmptyList();
if (!(list instanceof Serializable)) return;
if (!(list instanceof Serializable && isTestSerialization())) return;
byte[] objekt = writeExternalFormToBytes((Serializable) list);
List list2 = (List) readExternalFormFromBytes(objekt);
@ -959,7 +959,7 @@ public abstract class AbstractTestList extends AbstractTestCollection {
throws IOException, ClassNotFoundException {
List list = makeFullList();
int size = getFullElements().length;
if (!(list instanceof Serializable)) return;
if (!(list instanceof Serializable && isTestSerialization())) return;
byte[] objekt = writeExternalFormToBytes((Serializable) list);
List list2 = (List) readExternalFormFromBytes(objekt);
@ -983,7 +983,7 @@ public abstract class AbstractTestList extends AbstractTestCollection {
// test to make sure the canonical form has been preserved
List list = makeEmptyList();
if(list instanceof Serializable && !skipSerializedCanonicalTests()) {
if(list instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
List list2 = (List) readExternalFormFromDisk(getCanonicalEmptyCollectionName(list));
assertTrue("List is empty",list2.size() == 0);
assertEquals(list, list2);
@ -1005,7 +1005,7 @@ public abstract class AbstractTestList extends AbstractTestCollection {
// test to make sure the canonical form has been preserved
List list = makeFullList();
if(list instanceof Serializable && !skipSerializedCanonicalTests()) {
if(list instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
List list2 = (List) readExternalFormFromDisk(getCanonicalFullCollectionName(list));
if (list2.size() == 4) {
// old serialized tests
@ -1098,6 +1098,9 @@ public abstract class AbstractTestList extends AbstractTestCollection {
outer.verify();
}
public boolean isTestSerialization() {
return false;
}
}

View File

@ -117,7 +117,7 @@ import org.apache.commons.collections.set.AbstractTestSet;
* @author Rodney Waldhoff
* @author Paul Jack
* @author Stephen Colebourne
* @version $Revision: 1.14 $ $Date: 2004/04/12 12:04:00 $
* @version $Revision: 1.15 $ $Date: 2004/05/31 22:39:20 $
*/
public abstract class AbstractTestMap extends AbstractTestObject {
@ -739,7 +739,7 @@ public abstract class AbstractTestMap extends AbstractTestObject {
// test to make sure the canonical form has been preserved
Map map = makeEmptyMap();
if (map instanceof Serializable && !skipSerializedCanonicalTests()) {
if (map instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
Map map2 = (Map) readExternalFormFromDisk(getCanonicalEmptyCollectionName(map));
assertEquals("Map is empty", 0, map2.size());
}
@ -760,7 +760,7 @@ public abstract class AbstractTestMap extends AbstractTestObject {
// test to make sure the canonical form has been preserved
Map map = makeFullMap();
if (map instanceof Serializable && !skipSerializedCanonicalTests()) {
if (map instanceof Serializable && !skipSerializedCanonicalTests() && isTestSerialization()) {
Map map2 = (Map) readExternalFormFromDisk(getCanonicalFullCollectionName(map));
assertEquals("Map is the right size", getSampleKeys().length, map2.size());
}
@ -1255,13 +1255,10 @@ public abstract class AbstractTestMap extends AbstractTestObject {
public boolean isGetStructuralModify() {
return AbstractTestMap.this.isGetStructuralModify();
}
public boolean supportsEmptyCollections() {
return AbstractTestMap.this.supportsEmptyCollections();
public boolean isTestSerialization() {
return false;
}
public boolean supportsFullCollections() {
return AbstractTestMap.this.supportsFullCollections();
}
public void resetFull() {
AbstractTestMap.this.resetFull();
collection = map.entrySet();
@ -1415,11 +1412,8 @@ public abstract class AbstractTestMap extends AbstractTestObject {
public boolean isRemoveSupported() {
return AbstractTestMap.this.isRemoveSupported();
}
public boolean supportsEmptyCollections() {
return AbstractTestMap.this.supportsEmptyCollections();
}
public boolean supportsFullCollections() {
return AbstractTestMap.this.supportsFullCollections();
public boolean isTestSerialization() {
return false;
}
public void resetEmpty() {
@ -1484,13 +1478,10 @@ public abstract class AbstractTestMap extends AbstractTestObject {
public boolean isRemoveSupported() {
return AbstractTestMap.this.isRemoveSupported();
}
public boolean supportsEmptyCollections() {
return AbstractTestMap.this.supportsEmptyCollections();
public boolean isTestSerialization() {
return false;
}
public boolean supportsFullCollections() {
return AbstractTestMap.this.supportsFullCollections();
}
public boolean areEqualElementsDistinguishable() {
// equal values are associated with different keys, so they are
// distinguishable.

View File

@ -28,7 +28,7 @@ import org.apache.commons.collections.BulkTest;
/**
* Abstract test class for {@link java.util.SortedMap} methods and contracts.
*
* @version $Revision: 1.8 $ $Date: 2004/04/09 15:17:11 $
* @version $Revision: 1.9 $ $Date: 2004/05/31 22:39:20 $
*
* @author Stephen Colebourne
*/
@ -155,28 +155,25 @@ public abstract class AbstractTestSortedMap extends AbstractTestMap {
public boolean isRemoveSupported() {
return main.isRemoveSupported();
}
public boolean supportsEmptyCollections() {
public boolean isTestSerialization() {
return false;
}
public boolean supportsFullCollections() {
return false;
}
public void testSimpleSerialization() throws Exception {
if (main.isSubMapViewsSerializable() == false) return;
super.testSimpleSerialization();
}
public void testSerializeDeserializeThenCompare() throws Exception {
if (main.isSubMapViewsSerializable() == false) return;
super.testSerializeDeserializeThenCompare();
}
public void testEmptyMapCompatibility() throws Exception {
if (main.isSubMapViewsSerializable() == false) return;
super.testEmptyMapCompatibility();
}
public void testFullMapCompatibility() throws Exception {
if (main.isSubMapViewsSerializable() == false) return;
super.testFullMapCompatibility();
}
// public void testSimpleSerialization() throws Exception {
// if (main.isSubMapViewsSerializable() == false) return;
// super.testSimpleSerialization();
// }
// public void testSerializeDeserializeThenCompare() throws Exception {
// if (main.isSubMapViewsSerializable() == false) return;
// super.testSerializeDeserializeThenCompare();
// }
// public void testEmptyMapCompatibility() throws Exception {
// if (main.isSubMapViewsSerializable() == false) return;
// super.testEmptyMapCompatibility();
// }
// public void testFullMapCompatibility() throws Exception {
// if (main.isSubMapViewsSerializable() == false) return;
// super.testFullMapCompatibility();
// }
}
public static class TestHeadMap extends TestViewMap {

View File

@ -32,7 +32,7 @@ import org.apache.commons.collections.list.AbstractTestList;
/**
* JUnit tests.
*
* @version $Revision: 1.7 $ $Date: 2004/02/27 00:25:14 $
* @version $Revision: 1.8 $ $Date: 2004/05/31 22:39:20 $
*
* @author Stephen Colebourne
*/
@ -252,7 +252,9 @@ public class TestLinkedMap extends AbstractTestOrderedMap {
public boolean isNullSupported() {
return TestLinkedMap.this.isAllowNullKey();
}
public boolean isTestSerialization() {
return false;
}
}
public void testClone() {

View File

@ -31,7 +31,7 @@ import org.apache.commons.collections.list.AbstractTestList;
* implementation.
*
* @since Commons Collections 3.0
* @version $Revision: 1.9 $ $Date: 2004/04/07 23:17:25 $
* @version $Revision: 1.10 $ $Date: 2004/05/31 22:39:20 $
*
* @author Henri Yandell
* @author Stephen Colebourne
@ -188,7 +188,9 @@ public class TestListOrderedMap extends AbstractTestOrderedMap {
public boolean isNullSupported() {
return TestListOrderedMap.this.isAllowNullKey();
}
public boolean isTestSerialization() {
return false;
}
}
public String getCompatibilityVersion() {

View File

@ -32,7 +32,7 @@ import org.apache.commons.collections.BulkTest;
* elements may be added; see {@link AbstractTestCollection} for more details.
*
* @since Commons Collections 3.0
* @version $Revision: 1.5 $ $Date: 2004/02/18 01:20:39 $
* @version $Revision: 1.6 $ $Date: 2004/05/31 22:39:20 $
*
* @author Stephen Colebourne
* @author Dieter Wimberger
@ -284,7 +284,11 @@ public abstract class AbstractTestSortedSet extends AbstractTestSet {
SortedSet s = (SortedSet) AbstractTestSortedSet.this.makeFullCollection();
return getSubSet(s);
}
public boolean isTestSerialization() {
return false;
}
public BulkTest bulkTestSortedSetSubSet() {
return null; // prevent infinite recursion
}