View Javadoc
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 com.google.common.annotations.GwtCompatible;
20  import java.util.ArrayList;
21  import java.util.List;
22  import java.util.ListIterator;
23  
24  /**
25   * A utility similar to {@link IteratorTester} for testing a
26   * {@link ListIterator} against a known good reference implementation. As with
27   * {@code IteratorTester}, a concrete subclass must provide target iterators on
28   * demand. It also requires three additional constructor parameters:
29   * {@code elementsToInsert}, the elements to be passed to {@code set()} and
30   * {@code add()} calls; {@code features}, the features supported by the
31   * iterator; and {@code expectedElements}, the elements the iterator should
32   * return in order.
33   * <p>
34   * The items in {@code elementsToInsert} will be repeated if {@code steps} is
35   * larger than the number of provided elements.
36   *
37   * @author Chris Povirk
38   */
39  @GwtCompatible
40  public abstract class ListIteratorTester<E> extends AbstractIteratorTester<E, ListIterator<E>> {
41    protected ListIteratorTester(
42        int steps,
43        Iterable<E> elementsToInsert,
44        Iterable<? extends IteratorFeature> features,
45        Iterable<E> expectedElements,
46        int startIndex) {
47      super(steps, elementsToInsert, features, expectedElements, KnownOrder.KNOWN_ORDER, startIndex);
48    }
49  
50    @Override
51    protected final Iterable<? extends Stimulus<E, ? super ListIterator<E>>> getStimulusValues() {
52      List<Stimulus<E, ? super ListIterator<E>>> list = new ArrayList<>();
53      Helpers.addAll(list, iteratorStimuli());
54      Helpers.addAll(list, listIteratorStimuli());
55      return list;
56    }
57  
58    @Override
59    protected abstract ListIterator<E> newTargetIterator();
60  }