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 (Iterator
orListIterator
)
- Direct Known Subclasses:
IteratorTester
,ListIteratorTester
@GwtCompatible abstract class AbstractIteratorTester<E,I extends java.util.Iterator<E>> extends java.lang.Object
Most of the logic forIteratorTester
andListIteratorTester
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interface
AbstractIteratorTester.IteratorOperation
static class
AbstractIteratorTester.KnownOrder
protected class
AbstractIteratorTester.MultiExceptionListIterator
Quasi-implementation ofListIterator
that works from a list of elements and a set of features to support (from the enclosingAbstractIteratorTester
instance).private static class
AbstractIteratorTester.PermittedMetaException
Meta-exception thrown byAbstractIteratorTester.MultiExceptionListIterator
instead of throwing any particular exception type.(package private) static class
AbstractIteratorTester.Stimulus<E,T extends java.util.Iterator<E>>
private static class
AbstractIteratorTester.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 void
compareResultsForThisListOfStimuli()
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.IteratorOperation
newAddMethod()
private AbstractIteratorTester.IteratorOperation
newSetMethod()
protected abstract I
newTargetIterator()
Returns a new target iterator each time it's called.private void
recurse(int level)
private static java.util.List<java.lang.Object>
subListCopy(java.lang.Object[] source, int size)
void
test()
Executes the test.void
testForEachRemaining()
protected void
verify(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()
-
-