Keel 2.1RC2

org.apache.commons.collections
Class TestList

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.apache.commons.collections.BulkTest
              extended byorg.apache.commons.collections.TestObject
                  extended byorg.apache.commons.collections.TestCollection
                      extended byorg.apache.commons.collections.TestList
All Implemented Interfaces:
java.lang.Cloneable, junit.framework.Test
Direct Known Subclasses:
TestArrayList, TestCursorableLinkedList, TestList.BulkTestSubList

public abstract class TestList
extends TestCollection

Tests base List methods and contracts.

To use, simply extend this class, and implement the #makeList method.

If your TestList.BulkTestSubList fails one of these tests by design, you may still use this base set of cases. Simply override the test case (method) your TestList.BulkTestSubList fails.

Version:
$Id: TestList.java,v 1.13 2002/10/13 13:55:35 scolebourne Exp $
Author:
Rodney Waldhoff, Paul Jack

Nested Class Summary
(package private) static class TestList.BulkTestSubList
           
 
Field Summary
 
Fields inherited from class org.apache.commons.collections.TestCollection
collection, confirmed
 
Fields inherited from class org.apache.commons.collections.TestObject
COLLECTIONS_MAJOR_VERSION
 
Fields inherited from class org.apache.commons.collections.BulkTest
verboseName
 
Fields inherited from class junit.framework.TestCase
 
Constructor Summary
TestList(java.lang.String testName)
           
 
Method Summary
private  void backwardTest(java.util.ListIterator iter, int i)
          Traverses to the beginning of the given iterator.
 BulkTest bulkTestSubList()
          Returns a BulkTest for testing List#subList(int,int).
protected  void failFastAll(java.util.List list)
          Invokes all the methods on the given sublist to make sure they raise a ConcurrentModificationException.
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 a ConcurrentModificationException.
private  void forwardTest(java.util.ListIterator iter, int i)
          Traverses to the end of the given iterator.
protected  java.util.List getConfirmedList()
          Returns the confirmed field cast to a TestList.BulkTestSubList.
protected  java.util.List getList()
          Returns the collection field cast to a TestList.BulkTestSubList.
protected  java.util.Collection makeCollection()
          Returns makeEmptyList().
protected  java.util.Collection makeConfirmedCollection()
          Returns an empty ArrayList.
protected  java.util.Collection makeConfirmedFullCollection()
          Returns a full ArrayList.
protected abstract  java.util.List makeEmptyList()
          Return a new, empty TestList.BulkTestSubList to be used for testing.
protected  java.util.Collection makeFullCollection()
          Returns makeFullList().
protected  java.util.List makeFullList()
          Return a new, full TestList.BulkTestSubList to be used for testing.
 void testEmptyListCompatibility()
          Compare the current serialized form of the List against the canonical version in CVS.
 void testEmptyListSerialization()
           
 void testFullListCompatibility()
          Compare the current serialized form of the List against the canonical version in CVS.
 void testFullListSerialization()
           
 void testListAddByIndex()
          Tests List#add(int,Object).
 void testListAddByIndexBoundsChecking()
          Tests bounds checking for List#add(int, Object) on an empty list.
 void testListAddByIndexBoundsChecking2()
          Tests bounds checking for List#add(int, Object) on a full list.
 void testListEquals()
          Tests Object.equals(Object).
 void testListGetByIndex()
          Tests List#get(int).
 void testListGetByIndexBoundsChecking()
          Tests bounds checking for List#get(int) on an empty list.
 void testListGetByIndexBoundsChecking2()
          Tests bounds checking for List#get(int) on a full list.
 void testListHashCode()
          Tests Object.hashCode().
 void testListIndexOf()
          Tests List#indexOf().
 void testListIteratorAdd()
          Tests the ListIterator.add(Object) method of the list iterator.
 void testListIteratorSet()
          Tests the ListIterator.set(Object) method of the list iterator.
 void testListLastIndexOf()
          Tests List#lastIndexOf().
 void testListListIterator()
          Tests the read-only bits of List#listIterator().
 void testListListIteratorByIndex()
          Tests the read-only bits of List#listIterator(int).
 void testListRemoveByIndex()
          Tests List#remove(int).
 void testListRemoveByIndexBoundsChecking()
          Tests bounds checking for List#remove(int) on an empty list.
 void testListRemoveByIndexBoundsChecking2()
          Tests bounds checking for List#remove(int) on a full list.
 void testListSetByIndex()
          Test List#set(int,Object).
 void testListSetByIndexBoundsChecking()
          Tests bounds checking for List#set(int,Object) on an empty list.
 void testListSetByIndexBoundsChecking2()
          Tests bounds checking for List#set(int,Object) on a full list.
 void testListSubListFailFastOnAdd()
          Tests that a sublist raises a ConcurrentModificationException if elements are added to the original list.
 void testListSubListFailFastOnRemove()
          Tests that a sublist raises a ConcurrentModificationException if elements are removed from the original list.
protected  void verify()
          Verifies that the test list implementation matches the confirmed list implementation.
 
Methods inherited from class org.apache.commons.collections.TestCollection
areEqualElementsDistinguishable, getFullElements, getFullNonNullElements, getFullNonNullStringElements, getOtherElements, getOtherNonNullElements, getOtherNonNullStringElements, isAddSupported, isRemoveSupported, makeObject, resetEmpty, resetFull, testCollectionAdd, testCollectionAddAll, testCollectionClear, testCollectionContains, testCollectionContainsAll, testCollectionIsEmpty, testCollectionIterator, testCollectionIteratorFailFast, testCollectionIteratorRemove, testCollectionRemove, testCollectionRemoveAll, testCollectionRetainAll, testCollectionSize, testCollectionToArray, testCollectionToArray2, testCollectionToString, testUnsupportedAdd, testUnsupportedRemove
 
Methods inherited from class org.apache.commons.collections.TestObject
getCanonicalEmptyCollectionName, getCanonicalFullCollectionName, getCompatibilityVersion, readExternalFormFromBytes, readExternalFormFromDisk, supportsEmptyCollections, supportsFullCollections, testCanonicalEmptyCollectionExists, testCanonicalFullCollectionExists, testObjectEqualsSelf, testObjectHashCodeEqualsContract, testObjectHashCodeEqualsSelfHashCode, testSimpleSerialization, writeExternalFormToBytes, writeExternalFormToDisk
 
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
 

Constructor Detail

TestList

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

makeEmptyList

protected abstract java.util.List makeEmptyList()
Return a new, empty TestList.BulkTestSubList to be used for testing.

Returns:
an empty list for testing.

makeFullList

protected java.util.List makeFullList()
Return a new, full TestList.BulkTestSubList to be used for testing.

Returns:
a full list for testing

makeCollection

protected final java.util.Collection makeCollection()
Returns makeEmptyList().

Specified by:
makeCollection in class TestCollection
Returns:
an empty list to be used for testing

makeFullCollection

protected final java.util.Collection makeFullCollection()
Returns makeFullList().

Overrides:
makeFullCollection in class TestCollection
Returns:
a full list to be used for testing

getList

protected java.util.List getList()
Returns the collection field cast to a TestList.BulkTestSubList.

Returns:
the collection field as a List

getConfirmedList

protected java.util.List getConfirmedList()
Returns the confirmed field cast to a TestList.BulkTestSubList.

Returns:
the confirmed field as a List

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.


testListAddByIndex

public void testListAddByIndex()
Tests List#add(int,Object).


testListEquals

public void testListEquals()
Tests Object.equals(Object).


testListHashCode

public void testListHashCode()
Tests Object.hashCode().


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.


testListIndexOf

public void testListIndexOf()
Tests List#indexOf().


testListLastIndexOf

public void testListLastIndexOf()
Tests List#lastIndexOf().


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.


testListSetByIndex

public void testListSetByIndex()
Test List#set(int,Object).


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.


testListRemoveByIndex

public void testListRemoveByIndex()
Tests List#remove(int).


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).


forwardTest

private void forwardTest(java.util.ListIterator iter,
                         int i)
Traverses to the end of the given iterator.

Parameters:
iter - the iterator to traverse
i - the starting index

backwardTest

private void backwardTest(java.util.ListIterator iter,
                          int i)
Traverses to the beginning of the given iterator.

Parameters:
iter - the iterator to traverse
i - the starting index

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.


testEmptyListSerialization

public void testEmptyListSerialization()
                                throws java.io.IOException,
                                       java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

testFullListSerialization

public void testFullListSerialization()
                               throws java.io.IOException,
                                      java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

testEmptyListCompatibility

public void testEmptyListCompatibility()
                                throws java.io.IOException,
                                       java.lang.ClassNotFoundException
Compare the current serialized form of the List against the canonical version in CVS.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

testFullListCompatibility

public void testFullListCompatibility()
                               throws java.io.IOException,
                                      java.lang.ClassNotFoundException
Compare the current serialized form of the List against the canonical version in CVS.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

makeConfirmedCollection

protected java.util.Collection makeConfirmedCollection()
Returns an empty ArrayList.

Specified by:
makeConfirmedCollection in class TestCollection
Returns:
a confirmed empty collection

makeConfirmedFullCollection

protected java.util.Collection makeConfirmedFullCollection()
Returns a full ArrayList.

Specified by:
makeConfirmedFullCollection in class TestCollection
Returns:
a confirmed full collection

verify

protected void verify()
Verifies that the test list implementation matches the confirmed list implementation.

Overrides:
verify in class TestCollection

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.


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.


failFastAll

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


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 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.

Parameters:
list - the sublist to test
m - the method to invoke

Keel 2.1RC2

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