Class AbstractTestList
- java.lang.Object
-
- junit.framework.Assert
-
- junit.framework.TestCase
-
- org.apache.commons.collections.BulkTest
-
- org.apache.commons.collections.AbstractTestObject
-
- org.apache.commons.collections.collection.AbstractTestCollection
-
- org.apache.commons.collections.list.AbstractTestList
-
- All Implemented Interfaces:
java.lang.Cloneable,junit.framework.Test
- Direct Known Subclasses:
AbstractTestList.BulkTestSubList
public abstract class AbstractTestList extends AbstractTestCollection
Abstract test class forListmethods and contracts.To use, simply extend this class, and implement the
makeEmptyList()method.If your
Listfails one of these tests by design, you may still use this base set of cases. Simply override the test case (method) yourListfails or override one of the protected methods from AbstractTestCollection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractTestList.BulkTestSubListclassAbstractTestList.TestListIterator
-
Field Summary
-
Fields inherited from class org.apache.commons.collections.collection.AbstractTestCollection
collection, confirmed
-
Fields inherited from class org.apache.commons.collections.AbstractTestObject
COLLECTIONS_MAJOR_VERSION
-
-
Constructor Summary
Constructors Constructor Description AbstractTestList(java.lang.String testName)JUnit constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description BulkTestbulkTestListIterator()BulkTestbulkTestSubList()Returns aBulkTestfor testingList.subList(int,int).protected voidfailFastAll(java.util.List list)Invokes all the methods on the given sublist to make sure they raise aConcurrentModificationException.protected voidfailFastMethod(java.util.List list, java.lang.reflect.Method m)Invokes the given method on the given sublist to make sure it raises aConcurrentModificationException.java.util.ListgetConfirmedList()Returns theAbstractTestCollection.confirmedfield cast to aList.java.util.ListgetList()Returns theAbstractTestCollection.collectionfield cast to aList.booleanisEqualsCheckable()List equals method is defined.booleanisSetSupported()Returns true if the collections produced bymakeCollection()andmakeFullCollection()support theset operation.java.util.CollectionmakeCollection()ReturnsmakeEmptyList().java.util.CollectionmakeConfirmedCollection()Returns an emptyArrayList.java.util.CollectionmakeConfirmedFullCollection()Returns a fullArrayList.abstract java.util.ListmakeEmptyList()Return a new, emptyListto be used for testing.java.util.CollectionmakeFullCollection()ReturnsmakeFullList().java.util.ListmakeFullList()Return a new, fullListto be used for testing.voidtestEmptyListCompatibility()Compare the current serialized form of the List against the canonical version in CVS.voidtestEmptyListSerialization()voidtestFullListCompatibility()Compare the current serialized form of the List against the canonical version in CVS.voidtestFullListSerialization()voidtestListAddByIndex()TestsList.add(int,Object).voidtestListAddByIndexBoundsChecking()Tests bounds checking forList.add(int, Object)on an empty list.voidtestListAddByIndexBoundsChecking2()Tests bounds checking forList.add(int, Object)on a full list.voidtestListEquals()TestsList.equals(Object).voidtestListGetByIndex()TestsList.get(int).voidtestListGetByIndexBoundsChecking()Tests bounds checking forList.get(int)on an empty list.voidtestListGetByIndexBoundsChecking2()Tests bounds checking forList.get(int)on a full list.voidtestListHashCode()TestsList.hashCode().voidtestListIndexOf()TestsList.indexOf(java.lang.Object).voidtestListIteratorAdd()Tests theListIterator.add(Object)method of the list iterator.voidtestListIteratorSet()Tests theListIterator.set(Object)method of the list iterator.voidtestListLastIndexOf()TestsList.lastIndexOf(java.lang.Object).voidtestListListIterator()Tests the read-only bits ofList.listIterator().voidtestListListIteratorByIndex()Tests the read-only bits ofList.listIterator(int).voidtestListListIteratorNextRemoveNext()Tests remove on list iterator is correct.voidtestListListIteratorNextRemovePrevious()Tests remove on list iterator is correct.voidtestListListIteratorPreviousRemoveNext()Tests remove on list iterator is correct.voidtestListListIteratorPreviousRemovePrevious()Tests remove on list iterator is correct.voidtestListRemoveByIndex()TestsList.remove(int).voidtestListRemoveByIndexBoundsChecking()Tests bounds checking forList.remove(int)on an empty list.voidtestListRemoveByIndexBoundsChecking2()Tests bounds checking forList.remove(int)on a full list.voidtestListSetByIndex()TestList.set(int,Object).voidtestListSetByIndexBoundsChecking()Tests bounds checking forList.set(int,Object)on an empty list.voidtestListSetByIndexBoundsChecking2()Tests bounds checking forList.set(int,Object)on a full list.voidtestListSubListFailFastOnAdd()Tests that a sublist raises aConcurrentModificationExceptionif elements are added to the original list.voidtestListSubListFailFastOnRemove()Tests that a sublist raises aConcurrentModificationExceptionif elements are removed from the original list.voidtestUnsupportedSet()IfisSetSupported()returns false, tests that set operation raisesUnsupportedOperationException.voidverify()Verifies that the test list implementation matches the confirmed list implementation.-
Methods inherited from class org.apache.commons.collections.collection.AbstractTestCollection
areEqualElementsDistinguishable, cloneMapEntry, getFullElements, getFullNonNullElements, getFullNonNullStringElements, getOtherElements, getOtherNonNullElements, getOtherNonNullStringElements, isAddSupported, isFailFastSupported, isNullSupported, isRemoveSupported, makeObject, resetEmpty, resetFull, testCollectionAdd, testCollectionAddAll, testCollectionClear, testCollectionContains, testCollectionContainsAll, testCollectionIsEmpty, testCollectionIterator, testCollectionIteratorFailFast, testCollectionIteratorRemove, testCollectionRemove, testCollectionRemoveAll, testCollectionRetainAll, testCollectionSize, testCollectionToArray, testCollectionToArray2, testCollectionToString, testSerializeDeserializeThenCompare, testUnsupportedAdd, testUnsupportedRemove
-
Methods inherited from class org.apache.commons.collections.AbstractTestObject
getCanonicalEmptyCollectionName, getCanonicalFullCollectionName, getCompatibilityVersion, isTestSerialization, readExternalFormFromBytes, readExternalFormFromDisk, skipSerializedCanonicalTests, supportsEmptyCollections, supportsFullCollections, testCanonicalEmptyCollectionExists, testCanonicalFullCollectionExists, testEqualsNull, testObjectEqualsSelf, testObjectHashCodeEqualsContract, testObjectHashCodeEqualsSelfHashCode, testSimpleSerialization, writeExternalFormToBytes, writeExternalFormToDisk
-
Methods inherited from class org.apache.commons.collections.BulkTest
clone, ignoredTests, makeSuite, toString
-
Methods inherited from class junit.framework.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, setUp, tearDown
-
-
-
-
Method Detail
-
isSetSupported
public boolean isSetSupported()
Returns true if the collections produced bymakeCollection()andmakeFullCollection()support theset operation.Default implementation returns true. Override if your collection class does not support set.
-
verify
public void verify()
Verifies that the test list implementation matches the confirmed list implementation.- Overrides:
verifyin classAbstractTestCollection
-
isEqualsCheckable
public boolean isEqualsCheckable()
List equals method is defined.- Overrides:
isEqualsCheckablein classAbstractTestCollection
-
makeConfirmedCollection
public java.util.Collection makeConfirmedCollection()
Returns an emptyArrayList.- Specified by:
makeConfirmedCollectionin classAbstractTestCollection- Returns:
- a confirmed empty collection
-
makeConfirmedFullCollection
public java.util.Collection makeConfirmedFullCollection()
Returns a fullArrayList.- Specified by:
makeConfirmedFullCollectionin classAbstractTestCollection- Returns:
- a confirmed full collection
-
makeEmptyList
public abstract java.util.List makeEmptyList()
Return a new, emptyListto be used for testing.- Returns:
- an empty list for testing.
-
makeFullList
public java.util.List makeFullList()
Return a new, fullListto be used for testing.- Returns:
- a full list for testing
-
makeCollection
public final java.util.Collection makeCollection()
ReturnsmakeEmptyList().- Specified by:
makeCollectionin classAbstractTestCollection- Returns:
- an empty list to be used for testing
-
makeFullCollection
public final java.util.Collection makeFullCollection()
ReturnsmakeFullList().- Overrides:
makeFullCollectionin classAbstractTestCollection- Returns:
- a full list to be used for testing
-
getList
public java.util.List getList()
Returns theAbstractTestCollection.collectionfield cast to aList.- Returns:
- the collection field as a List
-
getConfirmedList
public java.util.List getConfirmedList()
Returns theAbstractTestCollection.confirmedfield cast to aList.- Returns:
- the confirmed field as a List
-
testListAddByIndexBoundsChecking
public void testListAddByIndexBoundsChecking()
Tests bounds checking forList.add(int, Object)on an empty list.
-
testListAddByIndexBoundsChecking2
public void testListAddByIndexBoundsChecking2()
Tests bounds checking forList.add(int, Object)on a full list.
-
testListAddByIndex
public void testListAddByIndex()
TestsList.add(int,Object).
-
testListEquals
public void testListEquals()
TestsList.equals(Object).
-
testListHashCode
public void testListHashCode()
TestsList.hashCode().
-
testListGetByIndex
public void testListGetByIndex()
TestsList.get(int).
-
testListGetByIndexBoundsChecking
public void testListGetByIndexBoundsChecking()
Tests bounds checking forList.get(int)on an empty list.
-
testListGetByIndexBoundsChecking2
public void testListGetByIndexBoundsChecking2()
Tests bounds checking forList.get(int)on a full list.
-
testListIndexOf
public void testListIndexOf()
TestsList.indexOf(java.lang.Object).
-
testListLastIndexOf
public void testListLastIndexOf()
TestsList.lastIndexOf(java.lang.Object).
-
testListSetByIndexBoundsChecking
public void testListSetByIndexBoundsChecking()
Tests bounds checking forList.set(int,Object)on an empty list.
-
testListSetByIndexBoundsChecking2
public void testListSetByIndexBoundsChecking2()
Tests bounds checking forList.set(int,Object)on a full list.
-
testListSetByIndex
public void testListSetByIndex()
TestList.set(int,Object).
-
testUnsupportedSet
public void testUnsupportedSet()
IfisSetSupported()returns false, tests that set operation raisesUnsupportedOperationException.
-
testListRemoveByIndexBoundsChecking
public void testListRemoveByIndexBoundsChecking()
Tests bounds checking forList.remove(int)on an empty list.
-
testListRemoveByIndexBoundsChecking2
public void testListRemoveByIndexBoundsChecking2()
Tests bounds checking forList.remove(int)on a full list.
-
testListRemoveByIndex
public void testListRemoveByIndex()
TestsList.remove(int).
-
testListListIterator
public void testListListIterator()
Tests the read-only bits ofList.listIterator().
-
testListListIteratorByIndex
public void testListListIteratorByIndex()
Tests the read-only bits ofList.listIterator(int).
-
testListListIteratorPreviousRemoveNext
public void testListListIteratorPreviousRemoveNext()
Tests remove on list iterator is correct.
-
testListListIteratorPreviousRemovePrevious
public void testListListIteratorPreviousRemovePrevious()
Tests remove on list iterator is correct.
-
testListListIteratorNextRemoveNext
public void testListListIteratorNextRemoveNext()
Tests remove on list iterator is correct.
-
testListListIteratorNextRemovePrevious
public void testListListIteratorNextRemovePrevious()
Tests remove on list iterator is correct.
-
testListIteratorAdd
public void testListIteratorAdd()
Tests theListIterator.add(Object)method of the list iterator.
-
testListIteratorSet
public void testListIteratorSet()
Tests theListIterator.set(Object)method of the list iterator.
-
testEmptyListSerialization
public void testEmptyListSerialization() throws java.io.IOException, java.lang.ClassNotFoundException- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
testFullListSerialization
public void testFullListSerialization() throws java.io.IOException, java.lang.ClassNotFoundException- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
testEmptyListCompatibility
public void testEmptyListCompatibility() throws java.io.IOException, java.lang.ClassNotFoundExceptionCompare the current serialized form of the List against the canonical version in CVS.- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
testFullListCompatibility
public void testFullListCompatibility() throws java.io.IOException, java.lang.ClassNotFoundExceptionCompare the current serialized form of the List against the canonical version in CVS.- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
bulkTestSubList
public BulkTest bulkTestSubList()
Returns aBulkTestfor testingList.subList(int,int). The returned bulk test will run through everyTestListmethod, including anotherbulkTestSubList. Sublists are tested until the size of the sublist is less than 10. Each sublist is 6 elements smaller than its parent list. (By default this means that two rounds of sublists will be tested). The verify() method is overloaded to test that the original list is modified when the sublist is.
-
testListSubListFailFastOnAdd
public void testListSubListFailFastOnAdd()
Tests that a sublist raises aConcurrentModificationExceptionif elements are added to the original list.
-
testListSubListFailFastOnRemove
public void testListSubListFailFastOnRemove()
Tests that a sublist raises aConcurrentModificationExceptionif elements are removed from the original list.
-
failFastAll
protected void failFastAll(java.util.List list)
Invokes all the methods on the given sublist to make sure they raise aConcurrentModificationException.
-
failFastMethod
protected void failFastMethod(java.util.List list, java.lang.reflect.Method m)Invokes the given method on the given sublist to make sure it raises aConcurrentModificationException. Unless the method happens to be the equals() method, in which case the test is skipped. There seems to be a bug in java.util.AbstractList.subList(int,int).equals(Object) -- it never raises a ConcurrentModificationException.- Parameters:
list- the sublist to testm- the method to invoke
-
bulkTestListIterator
public BulkTest bulkTestListIterator()
-
-