Abstract test class for
java.util.List
methods and contracts.
To use, simply extend this class, and implement
the
makeEmptyList()
method.
If your
List
fails one of these tests by design,
you may still use this base set of cases. Simply override the
test case (method) your
List
fails or override one of the
protected methods from AbstractTestCollection.
bulkTestListIterator
public BulkTest bulkTestListIterator()
bulkTestSubList
public BulkTest bulkTestSubList()
Returns a BulkTest
for testing 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 ConcurrentModificationException
.
failFastMethod
protected void failFastMethod(List list,
Method m)
Invokes the given method on the given sublist to make sure it raises
a 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.
list
- the sublist to testm
- the method to invoke
getConfirmedList
public List getConfirmedList()
Returns the AbstractTestList
field cast to a List
.
- the confirmed field as a List
getList
public List getList()
Returns the AbstractTestList
field cast to a List
.
- 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
makeCollection()
and
makeFullCollection()
support the
set operation.
Default implementation returns true. Override if your collection
class does not support set.
makeCollection
public final Collection makeCollection()
- an empty list to be used for testing
makeConfirmedCollection
public Collection makeConfirmedCollection()
Returns an empty ArrayList
.
makeConfirmedFullCollection
public Collection makeConfirmedFullCollection()
Returns a full ArrayList
.
makeEmptyList
public abstract List makeEmptyList()
Return a new, empty List
to be used for testing.
- an empty list for testing.
makeFullCollection
public final Collection makeFullCollection()
- a full list to be used for testing
makeFullList
public List makeFullList()
Return a new, full List
to be used for testing.
testEmptyListCompatibility
public void testEmptyListCompatibility()
throws IOException,
ClassNotFoundException
Compare the current serialized form of the List
against the canonical version in CVS.
testEmptyListSerialization
public void testEmptyListSerialization()
throws IOException,
ClassNotFoundException
testFullListCompatibility
public void testFullListCompatibility()
throws IOException,
ClassNotFoundException
Compare the current serialized form of the List
against the canonical version in CVS.
testFullListSerialization
public void testFullListSerialization()
throws IOException,
ClassNotFoundException
testListAddByIndex
public void testListAddByIndex()
Tests List.add(int,Object)
.
testListAddByIndexBoundsChecking
public void testListAddByIndexBoundsChecking()
Tests bounds checking for List.add(int, Object)
on an
empty list.
testListAddByIndexBoundsChecking2
public void testListAddByIndexBoundsChecking2()
Tests bounds checking for List.add(int, Object)
on a
full list.
testListEquals
public void testListEquals()
Tests List.equals(Object)
.
testListGetByIndex
public void testListGetByIndex()
Tests List.get(int)
.
testListGetByIndexBoundsChecking
public void testListGetByIndexBoundsChecking()
Tests bounds checking for List.get(int)
on an
empty list.
testListGetByIndexBoundsChecking2
public void testListGetByIndexBoundsChecking2()
Tests bounds checking for List.get(int)
on a
full list.
testListHashCode
public void testListHashCode()
Tests List.hashCode()
.
testListIndexOf
public void testListIndexOf()
Tests List.indexOf
.
testListIteratorAdd
public void testListIteratorAdd()
Tests the ListIterator.add(Object)
method of the list
iterator.
testListIteratorSet
public void testListIteratorSet()
Tests the ListIterator.set(Object)
method of the list
iterator.
testListLastIndexOf
public void testListLastIndexOf()
Tests List.lastIndexOf
.
testListListIterator
public void testListListIterator()
Tests the read-only bits of List.listIterator()
.
testListListIteratorByIndex
public void testListListIteratorByIndex()
Tests the read-only bits of List.listIterator(int)
.
testListListIteratorNextRemoveNext
public void testListListIteratorNextRemoveNext()
Tests remove on list iterator is correct.
testListListIteratorNextRemovePrevious
public void testListListIteratorNextRemovePrevious()
Tests remove on list iterator is correct.
testListListIteratorPreviousRemoveNext
public void testListListIteratorPreviousRemoveNext()
Tests remove on list iterator is correct.
testListListIteratorPreviousRemovePrevious
public void testListListIteratorPreviousRemovePrevious()
Tests remove on list iterator is correct.
testListRemoveByIndex
public void testListRemoveByIndex()
Tests List.remove(int)
.
testListRemoveByIndexBoundsChecking
public void testListRemoveByIndexBoundsChecking()
Tests bounds checking for List.remove(int)
on an
empty list.
testListRemoveByIndexBoundsChecking2
public void testListRemoveByIndexBoundsChecking2()
Tests bounds checking for List.remove(int)
on a
full list.
testListSetByIndex
public void testListSetByIndex()
Test List.set(int,Object)
.
testListSetByIndexBoundsChecking
public void testListSetByIndexBoundsChecking()
Tests bounds checking for List.set(int,Object)
on an
empty list.
testListSetByIndexBoundsChecking2
public void testListSetByIndexBoundsChecking2()
Tests bounds checking for List.set(int,Object)
on a
full list.
testListSubListFailFastOnAdd
public void testListSubListFailFastOnAdd()
Tests that a sublist raises a ConcurrentModificationException
if elements are added to the original list.
testListSubListFailFastOnRemove
public void testListSubListFailFastOnRemove()
Tests that a sublist raises a ConcurrentModificationException
if elements are removed from the original list.
testUnsupportedSet
public void testUnsupportedSet()
If
isSetSupported()
returns false, tests that set operation
raises
UnsupportedOperationException.
verify
public void verify()
Verifies that the test list implementation matches the confirmed list
implementation.