Class AbstractIteratorTester<E,I extends java.util.Iterator<E>>
- java.lang.Object
-
- com.google.common.collect.testing.AbstractIteratorTester<E,I>
-
- Type Parameters:
E- the type of element returned by the iteratorI- the type of the iterator (IteratororListIterator)
- Direct Known Subclasses:
IteratorTester,ListIteratorTester
abstract class AbstractIteratorTester<E,I extends java.util.Iterator<E>> extends java.lang.ObjectMost of the logic forIteratorTesterandListIteratorTester.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interfaceAbstractIteratorTester.IteratorOperationstatic classAbstractIteratorTester.KnownOrderprotected classAbstractIteratorTester.MultiExceptionListIteratorQuasi-implementation ofListIteratorthat works from a list of elements and a set of features to support (from the enclosingAbstractIteratorTesterinstance).private static classAbstractIteratorTester.PermittedMetaExceptionMeta-exception thrown byAbstractIteratorTester.MultiExceptionListIteratorinstead of throwing any particular exception type.(package private) static classAbstractIteratorTester.Stimulus<E,T extends java.util.Iterator<E>>private static classAbstractIteratorTester.UnknownElementException
-
Field Summary
-
Constructor Summary
Constructors Constructor Description AbstractIteratorTester(int steps, java.lang.Iterable<E> elementsToInsertIterable, java.lang.Iterable<? extends IteratorFeature> features, java.lang.Iterable<E> expectedElements, AbstractIteratorTester.KnownOrder knownOrder, int startIndex)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private voidcompareResultsForThisListOfStimuli()protected abstract java.lang.Iterable<? extends AbstractIteratorTester.Stimulus<E,? super I>>getStimulusValues()I'd like to make this a parameter to the constructor, but I can't because the stimulus instances refer tothis.private <T extends java.util.Iterator<E>>
voidinternalExecuteAndCompare(T reference, T target, AbstractIteratorTester.IteratorOperation method)Apply this method to both iterators and return normally only if both produce the same response.(package private) java.util.List<AbstractIteratorTester.Stimulus<E,java.util.Iterator<E>>>iteratorStimuli()(package private) java.util.List<AbstractIteratorTester.Stimulus<E,java.util.ListIterator<E>>>listIteratorStimuli()private AbstractIteratorTester.IteratorOperationnewAddMethod()private AbstractIteratorTester.IteratorOperationnewSetMethod()protected abstract InewTargetIterator()Returns a new target iterator each time it's called.private voidrecurse(int level)private static java.util.List<java.lang.Object>subListCopy(java.lang.Object[] source, int size)voidtest()Executes the test.voidtestForEachRemaining()protected voidverify(java.util.List<E> elements)Override this to verify anything after running a list of Stimuli.
-
-
-
Field Detail
-
stimuli
private AbstractIteratorTester.Stimulus<E,? super I extends java.util.Iterator<E>>[] stimuli
-
elementsToInsert
private final java.util.Iterator<E> elementsToInsert
-
features
private final java.util.Set<IteratorFeature> features
-
expectedElements
private final java.util.List<E> expectedElements
-
startIndex
private final int startIndex
-
knownOrder
private final AbstractIteratorTester.KnownOrder knownOrder
-
REMOVE_METHOD
private static final AbstractIteratorTester.IteratorOperation REMOVE_METHOD
-
NEXT_METHOD
private static final AbstractIteratorTester.IteratorOperation NEXT_METHOD
-
PREVIOUS_METHOD
private static final AbstractIteratorTester.IteratorOperation PREVIOUS_METHOD
-
hasNext
AbstractIteratorTester.Stimulus<E,java.util.Iterator<E>> hasNext
-
next
AbstractIteratorTester.Stimulus<E,java.util.Iterator<E>> next
-
remove
AbstractIteratorTester.Stimulus<E,java.util.Iterator<E>> remove
-
hasPrevious
AbstractIteratorTester.Stimulus<E,java.util.ListIterator<E>> hasPrevious
-
nextIndex
AbstractIteratorTester.Stimulus<E,java.util.ListIterator<E>> nextIndex
-
previousIndex
AbstractIteratorTester.Stimulus<E,java.util.ListIterator<E>> previousIndex
-
previous
AbstractIteratorTester.Stimulus<E,java.util.ListIterator<E>> previous
-
add
AbstractIteratorTester.Stimulus<E,java.util.ListIterator<E>> add
-
set
AbstractIteratorTester.Stimulus<E,java.util.ListIterator<E>> set
-
-
Constructor Detail
-
AbstractIteratorTester
AbstractIteratorTester(int steps, java.lang.Iterable<E> elementsToInsertIterable, java.lang.Iterable<? extends IteratorFeature> features, java.lang.Iterable<E> expectedElements, AbstractIteratorTester.KnownOrder knownOrder, int startIndex)
-
-
Method Detail
-
getStimulusValues
protected abstract java.lang.Iterable<? extends AbstractIteratorTester.Stimulus<E,? super I>> getStimulusValues()
I'd like to make this a parameter to the constructor, but I can't because the stimulus instances refer tothis.
-
newTargetIterator
protected abstract I 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.
-
verify
protected void verify(java.util.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 byremove(),set(), andadd()calls
-
test
public final void test()
Executes the test.
-
testForEachRemaining
public void testForEachRemaining()
-
recurse
private void recurse(int level)
-
compareResultsForThisListOfStimuli
private void compareResultsForThisListOfStimuli()
-
subListCopy
private static java.util.List<java.lang.Object> subListCopy(java.lang.Object[] source, int size)
-
internalExecuteAndCompare
private <T extends java.util.Iterator<E>> void internalExecuteAndCompare(T reference, T target, AbstractIteratorTester.IteratorOperation method)
Apply this method to both iterators and return normally only if both produce the same response.
-
newAddMethod
private final AbstractIteratorTester.IteratorOperation newAddMethod()
-
newSetMethod
private final AbstractIteratorTester.IteratorOperation newSetMethod()
-
iteratorStimuli
java.util.List<AbstractIteratorTester.Stimulus<E,java.util.Iterator<E>>> iteratorStimuli()
-
listIteratorStimuli
java.util.List<AbstractIteratorTester.Stimulus<E,java.util.ListIterator<E>>> listIteratorStimuli()
-
-