Keel 2.1RC2

org.apache.commons.collections
Class TestObject

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.apache.commons.collections.BulkTest
              extended byorg.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

Field Summary
static int COLLECTIONS_MAJOR_VERSION
           
 
Fields inherited from class org.apache.commons.collections.BulkTest
verboseName
 
Fields inherited from class junit.framework.TestCase
 
Constructor Summary
TestObject(java.lang.String testName)
           
 
Method Summary
 java.lang.String getCanonicalEmptyCollectionName(java.lang.Object object)
           
 java.lang.String getCanonicalFullCollectionName(java.lang.Object object)
           
 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.
abstract  java.lang.Object makeObject()
          Return a new, empty Object to used for testing.
protected  java.lang.Object readExternalFormFromBytes(byte[] b)
          Read a Serialized or Externalized Object from bytes.
protected  java.lang.Object readExternalFormFromDisk(java.lang.String path)
          Reads a Serialized or Externalized Object from disk.
private  java.lang.Object readExternalFormFromStream(java.io.InputStream stream)
           
 boolean supportsEmptyCollections()
          Override this method if a subclass is testing a Collections that cannot serialize an "empty" Collection (e.g.
 boolean supportsFullCollections()
          Override this method if a subclass is testing a Collections that cannot serialize a "full" Collection (e.g.
 void testCanonicalEmptyCollectionExists()
          If the test object is serializable, confirm that a canonical form exists in CVS
 void testCanonicalFullCollectionExists()
          If the test object is serializable, confirm that a canonical form exists in CVS
 void testObjectEqualsSelf()
           
 void testObjectHashCodeEqualsContract()
           
 void testObjectHashCodeEqualsSelfHashCode()
           
 void testSimpleSerialization()
          Sanity check method, makes sure that any Serializable class can be serialized and de-serialized in memory, using the handy makeObject() method
protected  byte[] writeExternalFormToBytes(java.io.Serializable o)
          Converts a Serializable or Externalizable object to bytes.
protected  void writeExternalFormToDisk(java.io.Serializable o, java.lang.String path)
          Write a Serializable or Externalizable object as a file at the given path.
private  void writeExternalFormToStream(java.io.Serializable o, java.io.OutputStream stream)
           
 
Methods inherited from class org.apache.commons.collections.BulkTest
clone, ignoredSimpleTests, makeSuite, toString
 
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
 

Field Detail

COLLECTIONS_MAJOR_VERSION

public static final int COLLECTIONS_MAJOR_VERSION
See Also:
Constant Field Values
Constructor Detail

TestObject

public TestObject(java.lang.String testName)
Method Detail

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


Keel 2.1RC2

Please see keelframework.org for information about new Keel releases.