org.apache.commons.collections.list

Class AbstractTestList

public abstract class AbstractTestList extends AbstractTestCollection

Abstract test class for {@link java.util.List} methods and contracts.

To use, simply extend this class, and implement the {@link #makeEmptyList} method.

If your {@link List} fails one of these tests by design, you may still use this base set of cases. Simply override the test case (method) your {@link List} fails or override one of the protected methods from AbstractTestCollection.

Nested Class Summary
static classAbstractTestList.BulkTestSubList
classAbstractTestList.TestListIterator
Constructor Summary
AbstractTestList(String testName)
JUnit constructor.
Method Summary
BulkTestbulkTestListIterator()
BulkTestbulkTestSubList()
Returns a {@link BulkTest} for testing {@link List#subList(int,int)}.
protected voidfailFastAll(List list)
Invokes all the methods on the given sublist to make sure they raise a {@link java.util.ConcurrentModificationException ConcurrentModificationException}.
protected voidfailFastMethod(List list, Method m)
Invokes the given method on the given sublist to make sure it raises a {@link java.util.ConcurrentModificationException ConcurrentModificationException}.
ListgetConfirmedList()
Returns the {@link #confirmed} field cast to a {@link List}.
ListgetList()
Returns the {@link #collection} field cast to a {@link List}.
booleanisEqualsCheckable()
List equals method is defined.
booleanisSetSupported()
Returns true if the collections produced by {@link #makeCollection()} and {@link #makeFullCollection()} support the set operation.

Default implementation returns true.

CollectionmakeCollection()
Returns {@link #makeEmptyList()}.
CollectionmakeConfirmedCollection()
Returns an empty {@link ArrayList}.
CollectionmakeConfirmedFullCollection()
Returns a full {@link ArrayList}.
abstract ListmakeEmptyList()
Return a new, empty {@link List} to be used for testing.
CollectionmakeFullCollection()
Returns {@link #makeFullList()}.
ListmakeFullList()
Return a new, full {@link List} to 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()
Tests {@link List#add(int,Object)}.
voidtestListAddByIndexBoundsChecking()
Tests bounds checking for {@link List#add(int, Object)} on an empty list.
voidtestListAddByIndexBoundsChecking2()
Tests bounds checking for {@link List#add(int, Object)} on a full list.
voidtestListEquals()
Tests {@link List#equals(Object)}.
voidtestListGetByIndex()
Tests {@link List#get(int)}.
voidtestListGetByIndexBoundsChecking()
Tests bounds checking for {@link List#get(int)} on an empty list.
voidtestListGetByIndexBoundsChecking2()
Tests bounds checking for {@link List#get(int)} on a full list.
voidtestListHashCode()
Tests {@link List#hashCode()}.
voidtestListIndexOf()
Tests {@link List#indexOf}.
voidtestListIteratorAdd()
Tests the {@link ListIterator#add(Object)} method of the list iterator.
voidtestListIteratorSet()
Tests the {@link ListIterator#set(Object)} method of the list iterator.
voidtestListLastIndexOf()
Tests {@link List#lastIndexOf}.
voidtestListListIterator()
Tests the read-only bits of {@link List#listIterator()}.
voidtestListListIteratorByIndex()
Tests the read-only bits of {@link List#listIterator(int)}.
voidtestListListIteratorPreviousRemove()
Tests remove on list iterator is correct.
voidtestListRemoveByIndex()
Tests {@link List#remove(int)}.
voidtestListRemoveByIndexBoundsChecking()
Tests bounds checking for {@link List#remove(int)} on an empty list.
voidtestListRemoveByIndexBoundsChecking2()
Tests bounds checking for {@link List#remove(int)} on a full list.
voidtestListSetByIndex()
Test {@link List#set(int,Object)}.
voidtestListSetByIndexBoundsChecking()
Tests bounds checking for {@link List#set(int,Object)} on an empty list.
voidtestListSetByIndexBoundsChecking2()
Tests bounds checking for {@link List#set(int,Object)} on a full list.
voidtestListSubListFailFastOnAdd()
Tests that a sublist raises a {@link java.util.ConcurrentModificationException ConcurrentModificationException} if elements are added to the original list.
voidtestListSubListFailFastOnRemove()
Tests that a sublist raises a {@link java.util.ConcurrentModificationException ConcurrentModificationException} if elements are removed from the original list.
voidtestUnsupportedSet()
If {@link #isSetSupported()} returns false, tests that set operation raises UnsupportedOperationException.
voidverify()
Verifies that the test list implementation matches the confirmed list implementation.

Constructor Detail

AbstractTestList

public AbstractTestList(String testName)
JUnit constructor.

Parameters: testName the test class name

Method Detail

bulkTestListIterator

public BulkTest bulkTestListIterator()

bulkTestSubList

public BulkTest bulkTestSubList()
Returns a {@link BulkTest} for testing {@link List#subList(int,int)}. The returned bulk test will run through every TestList method, including another bulkTestSubList. 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.

failFastAll

protected void failFastAll(List list)
Invokes all the methods on the given sublist to make sure they raise a {@link java.util.ConcurrentModificationException ConcurrentModificationException}.

failFastMethod

protected void failFastMethod(List list, Method m)
Invokes the given method on the given sublist to make sure it raises a {@link java.util.ConcurrentModificationException ConcurrentModificationException}. 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 test m the method to invoke

getConfirmedList

public List getConfirmedList()
Returns the {@link #confirmed} field cast to a {@link List}.

Returns: the confirmed field as a List

getList

public List getList()
Returns the {@link #collection} field cast to a {@link List}.

Returns: the collection field as a List

isEqualsCheckable

public boolean isEqualsCheckable()
List equals method is defined.

isSetSupported

public boolean isSetSupported()
Returns true if the collections produced by {@link #makeCollection()} and {@link #makeFullCollection()} support the set operation.

Default implementation returns true. Override if your collection class does not support set.

makeCollection

public final Collection makeCollection()
Returns {@link #makeEmptyList()}.

Returns: an empty list to be used for testing

makeConfirmedCollection

public Collection makeConfirmedCollection()
Returns an empty {@link ArrayList}.

makeConfirmedFullCollection

public Collection makeConfirmedFullCollection()
Returns a full {@link ArrayList}.

makeEmptyList

public abstract List makeEmptyList()
Return a new, empty {@link List} to be used for testing.

Returns: an empty list for testing.

makeFullCollection

public final Collection makeFullCollection()
Returns {@link #makeFullList()}.

Returns: a full list to be used for testing

makeFullList

public List makeFullList()
Return a new, full {@link List} to be used for testing.

Returns: a full list for testing

testEmptyListCompatibility

public void testEmptyListCompatibility()
Compare the current serialized form of the List against the canonical version in CVS.

testEmptyListSerialization

public void testEmptyListSerialization()

testFullListCompatibility

public void testFullListCompatibility()
Compare the current serialized form of the List against the canonical version in CVS.

testFullListSerialization

public void testFullListSerialization()

testListAddByIndex

public void testListAddByIndex()
Tests {@link List#add(int,Object)}.

testListAddByIndexBoundsChecking

public void testListAddByIndexBoundsChecking()
Tests bounds checking for {@link List#add(int, Object)} on an empty list.

testListAddByIndexBoundsChecking2

public void testListAddByIndexBoundsChecking2()
Tests bounds checking for {@link List#add(int, Object)} on a full list.

testListEquals

public void testListEquals()
Tests {@link List#equals(Object)}.

testListGetByIndex

public void testListGetByIndex()
Tests {@link List#get(int)}.

testListGetByIndexBoundsChecking

public void testListGetByIndexBoundsChecking()
Tests bounds checking for {@link List#get(int)} on an empty list.

testListGetByIndexBoundsChecking2

public void testListGetByIndexBoundsChecking2()
Tests bounds checking for {@link List#get(int)} on a full list.

testListHashCode

public void testListHashCode()
Tests {@link List#hashCode()}.

testListIndexOf

public void testListIndexOf()
Tests {@link List#indexOf}.

testListIteratorAdd

public void testListIteratorAdd()
Tests the {@link ListIterator#add(Object)} method of the list iterator.

testListIteratorSet

public void testListIteratorSet()
Tests the {@link ListIterator#set(Object)} method of the list iterator.

testListLastIndexOf

public void testListLastIndexOf()
Tests {@link List#lastIndexOf}.

testListListIterator

public void testListListIterator()
Tests the read-only bits of {@link List#listIterator()}.

testListListIteratorByIndex

public void testListListIteratorByIndex()
Tests the read-only bits of {@link List#listIterator(int)}.

testListListIteratorPreviousRemove

public void testListListIteratorPreviousRemove()
Tests remove on list iterator is correct.

testListRemoveByIndex

public void testListRemoveByIndex()
Tests {@link List#remove(int)}.

testListRemoveByIndexBoundsChecking

public void testListRemoveByIndexBoundsChecking()
Tests bounds checking for {@link List#remove(int)} on an empty list.

testListRemoveByIndexBoundsChecking2

public void testListRemoveByIndexBoundsChecking2()
Tests bounds checking for {@link List#remove(int)} on a full list.

testListSetByIndex

public void testListSetByIndex()
Test {@link List#set(int,Object)}.

testListSetByIndexBoundsChecking

public void testListSetByIndexBoundsChecking()
Tests bounds checking for {@link List#set(int,Object)} on an empty list.

testListSetByIndexBoundsChecking2

public void testListSetByIndexBoundsChecking2()
Tests bounds checking for {@link List#set(int,Object)} on a full list.

testListSubListFailFastOnAdd

public void testListSubListFailFastOnAdd()
Tests that a sublist raises a {@link java.util.ConcurrentModificationException ConcurrentModificationException} if elements are added to the original list.

testListSubListFailFastOnRemove

public void testListSubListFailFastOnRemove()
Tests that a sublist raises a {@link java.util.ConcurrentModificationException ConcurrentModificationException} if elements are removed from the original list.

testUnsupportedSet

public void testUnsupportedSet()
If {@link #isSetSupported()} returns false, tests that set operation raises UnsupportedOperationException.

verify

public void verify()
Verifies that the test list implementation matches the confirmed list implementation.
Copyright © 2001-2007 Apache Software Foundation. All Rights Reserved.