com.google.common.collect.testing
Class ListIteratorTester<E>

java.lang.Object
  extended by com.google.common.collect.testing.ListIteratorTester<E>

@GwtCompatible
public abstract class ListIteratorTester<E>
extends Object

A utility similar to IteratorTester for testing a ListIterator against a known good reference implementation. As with IteratorTester, a concrete subclass must provide target iterators on demand. It also requires three additional constructor parameters: elementsToInsert, the elements to be passed to set() and add() calls; features, the features supported by the iterator; and expectedElements, the elements the iterator should return in order.

The items in elementsToInsert will be repeated if steps is larger than the number of provided elements.

This class is GWT compatible.

Author:
Chris Povirk

Nested Class Summary
static class AbstractIteratorTester.KnownOrder
           
 
Constructor Summary
protected ListIteratorTester(int steps, Iterable<E> elementsToInsert, Iterable<? extends IteratorFeature> features, Iterable<E> expectedElements, int startIndex)
           
 
Method Summary
protected  Iterable<? extends com.google.common.collect.testing.AbstractIteratorTester.Stimulus<E,? super ListIterator<E>>> getStimulusValues()
          I'd like to make this a parameter to the constructor, but I can't because the stimulus instances refer to this.
 void ignoreSunJavaBug6529795()
          Don't verify iterator behavior on remove() after a call to next() throws an exception.
protected abstract  ListIterator<E> newTargetIterator()
          Returns a new target iterator each time it's called.
 void stopTestingWhenAddThrowsException()
          Don't verify iterator behavior after a call to add() throws an exception.
 void test()
          Executes the test.
protected  void verify(List<E> elements)
          Override this to verify anything after running a list of Stimuli.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListIteratorTester

protected ListIteratorTester(int steps,
                             Iterable<E> elementsToInsert,
                             Iterable<? extends IteratorFeature> features,
                             Iterable<E> expectedElements,
                             int startIndex)
Method Detail

getStimulusValues

protected final Iterable<? extends com.google.common.collect.testing.AbstractIteratorTester.Stimulus<E,? super ListIterator<E>>> getStimulusValues()
I'd like to make this a parameter to the constructor, but I can't because the stimulus instances refer to this.


newTargetIterator

protected abstract ListIterator<E> newTargetIterator()
Returns a new target iterator each time it's called. This is the iterator you are trying to test. This must return an Iterator that returns the expected elements passed to the constructor in the given order. Warning: it is not enough to simply pull multiple iterators from the same source Iterable, unless that Iterator is unmodifiable.


ignoreSunJavaBug6529795

public void ignoreSunJavaBug6529795()
Don't verify iterator behavior on remove() after a call to next() throws an exception.

JDK 6 currently has a bug where some iterators get into a undefined state when next() throws a NoSuchElementException. The correct behavior is for remove() to remove the last element returned by next, even if a subsequent next() call threw an exception; however JDK 6's HashMap and related classes throw an IllegalStateException in this case.

Calling this method causes the iterator tester to skip testing any remove() in a stimulus sequence after the reference iterator throws an exception in next().

TODO: remove this once we're on 6u5, which has the fix.

See Also:
Sun Java Bug 6529795

stopTestingWhenAddThrowsException

public void stopTestingWhenAddThrowsException()
Don't verify iterator behavior after a call to add() throws an exception.

AbstractList's ListIterator implementation gets into a undefined state when add() throws an UnsupportedOperationException. Instead of leaving the iterator's position unmodified, it increments it, skipping an element or even moving past the end of the list.

Calling this method causes the iterator tester to skip testing in a stimulus sequence after the iterator under test throws an exception in add().

TODO: remove this once the behavior is fixed.

See Also:
Sun Java Bug 6533203

verify

protected void verify(List<E> elements)
Override this to verify anything after running a list of Stimuli.

For example, verify that calls to remove() actually removed the correct elements.

Parameters:
elements - the expected elements passed to the constructor, as mutated by remove(), set(), and add() calls

test

public final void test()
Executes the test.



Copyright © 2010-2012. All Rights Reserved.