org.apache.commons.collections
Class TestObject
java.lang.Object
junit.framework.Assert
junit.framework.TestCase
org.apache.commons.collections.BulkTest
org.apache.commons.collections.TestObject
- All Implemented Interfaces:
- java.lang.Cloneable, junit.framework.Test
- Direct Known Subclasses:
- TestBag, TestCollection, TestComparator, TestIterator, TestMap
- public abstract class TestObject
- extends BulkTest
Tests base Object methods and contracts.
To use, simply extend this class, and implement the makeObject() method.
If your Object fails one of these tests by design, you may still use this base set of cases. Simply override the test case (method) your Object fails.
- Version:
- $Id: TestObject.java,v 1.13 2002/10/13 13:55:35 scolebourne Exp $
- Author:
- Rodney Waldhoff
| Fields inherited from class junit.framework.TestCase |
|
| Constructor Summary |
TestObject(java.lang.String testName)
|
| Methods inherited from class junit.framework.TestCase |
countTestCases, createResult, getName, name, run, run, runBare, runTest, setName, setUp, tearDown |
| Methods inherited from class junit.framework.Assert |
assert, assert, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertNotNull, assertNotNull, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
COLLECTIONS_MAJOR_VERSION
public static final int COLLECTIONS_MAJOR_VERSION
-
- See Also:
- Constant Field Values
TestObject
public TestObject(java.lang.String testName)
getCompatibilityVersion
public int getCompatibilityVersion()
-
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. Defaults to 1, the earliest Collections version. (Note: some collections did not even exist in this version).
-
- Returns:
- 1
makeObject
public abstract java.lang.Object makeObject()
-
Return a new, empty
Object to used for testing.
-
testObjectEqualsSelf
public void testObjectEqualsSelf()
-
testObjectHashCodeEqualsSelfHashCode
public void testObjectHashCodeEqualsSelfHashCode()
-
testObjectHashCodeEqualsContract
public void testObjectHashCodeEqualsContract()
-
writeExternalFormToStream
private void writeExternalFormToStream(java.io.Serializable o,
java.io.OutputStream stream)
throws java.io.IOException
-
- Throws:
java.io.IOException
writeExternalFormToDisk
protected void writeExternalFormToDisk(java.io.Serializable o,
java.lang.String path)
throws java.io.IOException
-
Write a Serializable or Externalizable object as a file at the given path. NOT USEFUL as part of a unit test; this is just a utility method for creating disk-based objects in CVS that can become the basis for compatibility tests using readExternalFormFromDisk(String path)
-
- Parameters:
o - Object to serialize
path - path to write the serialized Object
- Throws:
java.io.IOException
writeExternalFormToBytes
protected byte[] writeExternalFormToBytes(java.io.Serializable o)
throws java.io.IOException
-
Converts a Serializable or Externalizable object to bytes. Useful for in-memory tests of serialization
-
- Parameters:
o - Object to convert to bytes
- Returns:
- serialized form of the Object
- Throws:
java.io.IOException
readExternalFormFromStream
private java.lang.Object readExternalFormFromStream(java.io.InputStream stream)
throws java.io.IOException,
java.lang.ClassNotFoundException
-
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
readExternalFormFromDisk
protected java.lang.Object readExternalFormFromDisk(java.lang.String path)
throws java.io.IOException,
java.lang.ClassNotFoundException
-
Reads a Serialized or Externalized Object from disk. Useful for creating compatibility tests betweeen different CVS versions of the same class
-
- Parameters:
path - path to the serialized Object
- Returns:
- the Object at the given path
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
readExternalFormFromBytes
protected java.lang.Object readExternalFormFromBytes(byte[] b)
throws java.io.IOException,
java.lang.ClassNotFoundException
-
Read a Serialized or Externalized Object from bytes. Useful for verifying serialization in memory.
-
- Parameters:
b - byte array containing a serialized Object
- Returns:
- Object contained in the bytes
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
testSimpleSerialization
public void testSimpleSerialization()
throws java.io.IOException,
java.lang.ClassNotFoundException
-
Sanity check method, makes sure that any Serializable class can be serialized and de-serialized in memory, using the handy makeObject() method
-
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
getCanonicalEmptyCollectionName
public java.lang.String getCanonicalEmptyCollectionName(java.lang.Object object)
-
getCanonicalFullCollectionName
public java.lang.String getCanonicalFullCollectionName(java.lang.Object object)
-
supportsEmptyCollections
public boolean supportsEmptyCollections()
-
Override this method if a subclass is testing a Collections that cannot serialize an "empty" Collection (e.g. Comparators have no contents)
-
- Returns:
- true
supportsFullCollections
public boolean supportsFullCollections()
-
Override this method if a subclass is testing a Collections that cannot serialize a "full" Collection (e.g. Comparators have no contents)
-
- Returns:
- true
testCanonicalEmptyCollectionExists
public void testCanonicalEmptyCollectionExists()
-
If the test object is serializable, confirm that a canonical form exists in CVS
-
testCanonicalFullCollectionExists
public void testCanonicalFullCollectionExists()
-
If the test object is serializable, confirm that a canonical form exists in CVS
-
Please see keelframework.org for information about new Keel releases.