| org.apache.commons.collections.AbstractTestObject org.apache.commons.collections.collection.AbstractTestCollection
All known Subclasses: org.apache.commons.collections.buffer.TestSynchronizedBuffer, org.apache.commons.collections.buffer.TestUnboundedFifoBuffer, org.apache.commons.collections.collection.TestTransformedCollection, org.apache.commons.collections.TestBoundedFifoBuffer, org.apache.commons.collections.collection.TestPredicatedCollection, org.apache.commons.collections.collection.TestUnmodifiableCollection, org.apache.commons.collections.buffer.TestPriorityBuffer, org.apache.commons.collections.TestBinaryHeap, org.apache.commons.collections.TestUnboundedFifoBuffer, org.apache.commons.collections.set.AbstractTestSet, org.apache.commons.collections.list.AbstractTestList, org.apache.commons.collections.collection.TestSynchronizedCollection, org.apache.commons.collections.buffer.TestBoundedFifoBuffer, org.apache.commons.collections.buffer.TestCircularFifoBuffer, org.apache.commons.collections.buffer.TestUnmodifiableBuffer, org.apache.commons.collections.collection.TestCompositeCollection,
AbstractTestCollection | abstract public class AbstractTestCollection extends AbstractTestObject (Code) | | Abstract test class for
java.util.Collection methods and contracts.
You should create a concrete subclass of this class to test any custom
Collection implementation. At minimum, you'll have to
implement the
AbstractTestCollection.makeCollection() method. You might want to
override some of the additional public methods as well:
Element Population Methods
Override these if your collection restricts what kind of elements are
allowed (for instance, if null is not permitted):
Supported Operation Methods
Override these if your collection doesn't support certain operations:
Fixture Methods
Fixtures are used to verify that the the operation results in correct state
for the collection. Basically, the operation is performed against your
collection implementation, and an identical operation is performed against a
confirmed collection implementation. A confirmed collection
implementation is something like java.util.ArrayList , which is
known to conform exactly to its collection interface's contract. After the
operation takes place on both your collection implementation and the
confirmed collection implementation, the two collections are compared to see
if their state is identical. The comparison is usually much more involved
than a simple equals test. This verification is used to ensure
proper modifications are made along with ensuring that the collection does
not change when read-only modifications are made.
The
AbstractTestCollection.collection field holds an instance of your collection
implementation; the
AbstractTestCollection.confirmed field holds an instance of the
confirmed collection implementation. The
AbstractTestCollection.resetEmpty() and
AbstractTestCollection.resetFull() methods set these fields to empty or full collections,
so that tests can proceed from a known state.
After a modification operation to both
AbstractTestCollection.collection and
AbstractTestCollection.confirmed , the
AbstractTestCollection.verify() method is invoked to compare
the results. You may want to override
AbstractTestCollection.verify() to perform
additional verifications. For instance, when testing the collection
views of a map,
AbstractTestMap would override
AbstractTestCollection.verify() to make
sure the map is changed after the collection view is changed.
If you're extending this class directly, you will have to provide
implementations for the following:
Those methods should provide a confirmed collection implementation
that's compatible with your collection implementation.
If you're extending
AbstractTestList ,
AbstractTestSet ,
or
AbstractTestBag , you probably don't have to worry about the
above methods, because those three classes already override the methods
to provide standard JDK confirmed collections.
Other notes
If your
Collection fails one of these tests by design,
you may still use this base set of cases. Simply override the
test case (method) your
Collection fails.
version: $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $ author: Rodney Waldhoff author: Paul Jack author: Michael A. Smith author: Neil O'Toole author: Stephen Colebourne |
collection | public Collection collection(Code) | | A collection instance that will be used for testing.
|
confirmed | public Collection confirmed(Code) | | Confirmed collection. This is an instance of a collection that is
confirmed to conform exactly to the java.util.Collection contract.
Modification operations are tested by performing a mod on your
collection, performing the exact same mod on an equivalent confirmed
collection, and then calling verify() to make sure your collection
still matches the confirmed collection.
|
AbstractTestCollection | public AbstractTestCollection(String testName)(Code) | | JUnit constructor.
Parameters: testName - the test class name |
areEqualElementsDistinguishable | public boolean areEqualElementsDistinguishable()(Code) | | Specifies whether equal elements in the collection are, in fact,
distinguishable with information not readily available. That is, if a
particular value is to be removed from the collection, then there is
one and only one value that can be removed, even if there are other
elements which are equal to it.
In most collection cases, elements are not distinguishable (equal is
equal), thus this method defaults to return false. In some cases,
however, they are. For example, the collection returned from the map's
values() collection view are backed by the map, so while there may be
two values that are equal, their associated keys are not. Since the
keys are distinguishable, the values are.
This flag is used to skip some verifications for iterator.remove()
where it is impossible to perform an equivalent modification on the
confirmed collection because it is not possible to determine which
value in the confirmed collection to actually remove. Tests that
override the default (i.e. where equal elements are distinguishable),
should provide additional tests on iterator.remove() to make sure the
proper elements are removed when remove() is called on the iterator.
|
cloneMapEntry | public Map.Entry cloneMapEntry(Map.Entry entry)(Code) | | Creates a new Map Entry that is independent of the first and the map.
|
getFullElements | public Object[] getFullElements()(Code) | | Returns an array of objects that are contained in a collection
produced by
AbstractTestCollection.makeFullCollection() . Every element in the
returned array must be an element in a full collection.
The default implementation returns a heterogenous array of
objects with some duplicates. null is added if allowed.
Override if you require specific testing elements. Note that if you
override
AbstractTestCollection.makeFullCollection() , you must override
this method to reflect the contents of a full collection.
|
getFullNonNullElements | public Object[] getFullNonNullElements()(Code) | | Returns a list of elements suitable for return by
AbstractTestCollection.getFullElements() . The array returned by this method
does not include null, but does include a variety of objects
of different types. Override getFullElements to return
the results of this method if your collection does not support
the null element.
|
getFullNonNullStringElements | public Object[] getFullNonNullStringElements()(Code) | | Returns a list of string elements suitable for return by
AbstractTestCollection.getFullElements() . Override getFullElements to return
the results of this method if your collection does not support
heterogenous elements or the null element.
|
getOtherElements | public Object[] getOtherElements()(Code) | | Returns an array of elements that are not contained in a
full collection. Every element in the returned array must
not exist in a collection returned by
AbstractTestCollection.makeFullCollection() .
The default implementation returns a heterogenous array of elements
without null. Note that some of the tests add these elements
to an empty or full collection, so if your collection restricts
certain kinds of elements, you should override this method.
|
getOtherNonNullStringElements | public Object[] getOtherNonNullStringElements()(Code) | | Returns a list of string elements suitable for return by
AbstractTestCollection.getOtherElements() . Override getOtherElements to return
the results of this method if your collection does not support
heterogenous elements or the null element.
|
isEqualsCheckable | public boolean isEqualsCheckable()(Code) | | Returns true to indicate that the collection supports equals() comparisons.
This implementation returns false;
|
isFailFastSupported | public boolean isFailFastSupported()(Code) | | Returns true to indicate that the collection supports fail fast iterators.
The default implementation returns true;
|
isNullSupported | public boolean isNullSupported()(Code) | | Returns true to indicate that the collection supports holding null.
The default implementation returns true;
|
makeObject | public Object makeObject()(Code) | | Returns an empty collection for Object tests.
|
testCollectionIteratorFailFast | public void testCollectionIteratorFailFast()(Code) | | Tests that the collection's iterator is fail-fast.
|
testCollectionToString | public void testCollectionToString()(Code) | | Tests toString on a collection.
|
testSerializeDeserializeThenCompare | public void testSerializeDeserializeThenCompare() throws Exception(Code) | | |
testUnsupportedRemove | public void testUnsupportedRemove()(Code) | | If isRemoveSupported() returns false, tests to see that remove
operations raise an UnsupportedOperationException.
|
Fields inherited from org.apache.commons.collections.AbstractTestObject | final public static int COLLECTIONS_MAJOR_VERSION(Code)(Java Doc)
|
|
|