Home | History | Annotate | Download | only in testing
      1 /*
      2  * Copyright (C) 2007 The Guava Authors
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.common.collect.testing;
     18 
     19 import java.util.ArrayList;
     20 import java.util.List;
     21 import java.util.ListIterator;
     22 
     23 /**
     24  * A utility similar to {@link IteratorTester} for testing a
     25  * {@link ListIterator} against a known good reference implementation. As with
     26  * {@code IteratorTester}, a concrete subclass must provide target iterators on
     27  * demand. It also requires three additional constructor parameters:
     28  * {@code elementsToInsert}, the elements to be passed to {@code set()} and
     29  * {@code add()} calls; {@code features}, the features supported by the
     30  * iterator; and {@code expectedElements}, the elements the iterator should
     31  * return in order.
     32  * <p>
     33  * The items in {@code elementsToInsert} will be repeated if {@code steps} is
     34  * larger than the number of provided elements.
     35  *
     36  * <p>This class is GWT compatible.
     37  *
     38  * @author Chris Povirk
     39  */
     40 public abstract class ListIteratorTester<E> extends
     41     AbstractIteratorTester<E, ListIterator<E>> {
     42   protected ListIteratorTester(int steps, Iterable<E> elementsToInsert,
     43       Iterable<? extends IteratorFeature> features,
     44       Iterable<E> expectedElements, int startIndex) {
     45     super(steps, elementsToInsert, features, expectedElements,
     46         KnownOrder.KNOWN_ORDER, startIndex);
     47   }
     48 
     49   @Override
     50   protected final Iterable<? extends Stimulus<E, ? super ListIterator<E>>>
     51       getStimulusValues() {
     52     List<Stimulus<E, ? super ListIterator<E>>> list =
     53         new ArrayList<Stimulus<E, ? super ListIterator<E>>>();
     54     Helpers.addAll(list, iteratorStimuli());
     55     Helpers.addAll(list, listIteratorStimuli());
     56     return list;
     57   }
     58 
     59   @Override protected abstract ListIterator<E> newTargetIterator();
     60 }
     61