org.apache.commons.collections.iterators
abstract public class: AbstractTestIterator [javadoc |
source]
java.lang.Object
junit.framework.TestCase
org.apache.commons.collections.BulkTest
org.apache.commons.collections.AbstractTestObject
org.apache.commons.collections.iterators.AbstractTestIterator
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
TestIntIterator, TestObjectArrayListIterator2, TestIteratorCharIterator, TestListIteratorFloatListIterator, TestUnmodifiableIterator, TestDoubleIteratorIterator, TestIteratorFloatIterator, TestSingletonIterator2, TestIteratorByteIterator, TestShortListIteratorListIterator, AbstractTestOrderedMapIterator, TestShortIteratorIterator, TestFloatListIterator, TestUnmodifiableMapIterator, InnerTestMapIterator, TestListIteratorShortListIterator, TestUnmodifiableOrderedMapIterator, TestByteIteratorIterator, TestIntListIteratorListIterator, TestListIteratorDoubleListIterator, TestCharListIterator, TestCharListIteratorListIterator, TestFloatListIteratorListIterator, AbstractTestMapIterator, TestLongIterator, TestIntListIterator, TestBidiOrderedMapIterator, TestIntIteratorIterator, TestFlatMapIterator, TestShortListIterator, TestDoubleListIterator, AbstractTestListIterator, TestIteratorIntIterator, TestObjectArrayIterator, TestCharIteratorIterator, TestShortIterator, TestListIteratorCharListIterator, TestObjectArrayListIterator, TestDoubleIterator, TestBidiMapIterator, TestLongIteratorIterator, TestCharIterator, TestReaderCharIterator, TestByteIterator, TestInputStreamByteIterator, TestListIteratorIntListIterator, TestListIteratorByteListIterator, TestFloatIteratorIterator, TestLongListIterator, TestFloatIterator, TestListIterator, TestUnmodifiableListIterator, TestListIteratorLongListIterator, TestIteratorShortIterator, TestIteratorLongIterator, InnerTestOrderedMapIterator, TestIteratorDoubleIterator, TestLongListIteratorListIterator, TestDoubleListIteratorListIterator, TestByteListIteratorListIterator, TestObjectGraphIterator, TestByteListIterator
Abstract class for testing the Iterator interface.
This class provides a framework for testing an implementation of Iterator.
Concrete subclasses must provide the iterator to be tested.
They must also specify certain details of how the iterator operates by
overriding the supportsXxx() methods if necessary.
- since:
Commons - Collections 3.0
- version:
$ - Revision: 1.8 $ $Date: 2004/02/18 01:20:33 $
- author:
Morgan - Delagrange
- author:
Stephen - Colebourne
| Methods from org.apache.commons.collections.AbstractTestObject: |
|---|
|
getCanonicalEmptyCollectionName, getCanonicalFullCollectionName, getCompatibilityVersion, isEqualsCheckable, isTestSerialization, makeObject, readExternalFormFromBytes, readExternalFormFromDisk, skipSerializedCanonicalTests, supportsEmptyCollections, supportsFullCollections, testCanonicalEmptyCollectionExists, testCanonicalFullCollectionExists, testEqualsNull, testObjectEqualsSelf, testObjectHashCodeEqualsContract, testObjectHashCodeEqualsSelfHashCode, testSerializeDeserializeThenCompare, testSimpleSerialization, writeExternalFormToBytes, writeExternalFormToDisk |
| Method from org.apache.commons.collections.iterators.AbstractTestIterator Detail: |
abstract public Iterator makeEmptyIterator()
Implement this method to return an iterator over an empty collection. |
abstract public Iterator makeFullIterator()
Implement this method to return an iterator over a collection with elements. |
public Object makeObject() {
return makeFullIterator();
}
Implements the abstract superclass method to return the full iterator. |
public boolean supportsEmptyIterator() {
return true;
}
Whether or not we are testing an iterator that can be empty.
Default is true. |
public boolean supportsFullIterator() {
return true;
}
Whether or not we are testing an iterator that can contain elements.
Default is true. |
public boolean supportsRemove() {
return true;
}
Whether or not we are testing an iterator that supports remove().
Default is true. |
public void testEmptyIterator() {
if (supportsEmptyIterator() == false) {
return;
}
Iterator it = makeEmptyIterator();
// hasNext() should return false
assertEquals("hasNext() should return false for empty iterators", false, it.hasNext());
// next() should throw a NoSuchElementException
try {
it.next();
fail("NoSuchElementException must be thrown when Iterator is exhausted");
} catch (NoSuchElementException e) {
}
verify();
assertNotNull(it.toString());
}
|
public void testFullIterator() {
if (supportsFullIterator() == false) {
return;
}
Iterator it = makeFullIterator();
// hasNext() must be true (ensure makeFullIterator is correct!)
assertEquals("hasNext() should return true for at least one element", true, it.hasNext());
// next() must not throw exception (ensure makeFullIterator is correct!)
try {
it.next();
} catch (NoSuchElementException e) {
fail("Full iterators must have at least one element");
}
// iterate through
while (it.hasNext()) {
it.next();
verify();
}
// next() must throw NoSuchElementException now
try {
it.next();
fail("NoSuchElementException must be thrown when Iterator is exhausted");
} catch (NoSuchElementException e) {
}
assertNotNull(it.toString());
}
Test normal iteration behaviour. |
public void testRemove() {
Iterator it = makeFullIterator();
if (supportsRemove() == false) {
// check for UnsupportedOperationException if not supported
try {
it.remove();
} catch (UnsupportedOperationException ex) {}
return;
}
// should throw IllegalStateException before next() called
try {
it.remove();
fail();
} catch (IllegalStateException ex) {}
verify();
// remove after next should be fine
it.next();
it.remove();
// should throw IllegalStateException for second remove()
try {
it.remove();
fail();
} catch (IllegalStateException ex) {}
}
|
public void verify() {
// do nothing
}
Allows subclasses to add complex cross verification |