001/* 002 * Copyright (C) 2007 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.google.common.collect.testing; 018 019import com.google.common.annotations.GwtCompatible; 020import java.util.ArrayList; 021import java.util.List; 022import java.util.ListIterator; 023 024/** 025 * A utility similar to {@link IteratorTester} for testing a {@link ListIterator} against a known 026 * good reference implementation. As with {@code IteratorTester}, a concrete subclass must provide 027 * target iterators on demand. It also requires three additional constructor parameters: {@code 028 * elementsToInsert}, the elements to be passed to {@code set()} and {@code add()} calls; {@code 029 * features}, the features supported by the iterator; and {@code expectedElements}, the elements the 030 * iterator should return in order. 031 * 032 * <p>The items in {@code elementsToInsert} will be repeated if {@code steps} is larger than the 033 * number of provided elements. 034 * 035 * @author Chris Povirk 036 */ 037@GwtCompatible 038public abstract class ListIteratorTester<E> extends AbstractIteratorTester<E, ListIterator<E>> { 039 protected ListIteratorTester( 040 int steps, 041 Iterable<E> elementsToInsert, 042 Iterable<? extends IteratorFeature> features, 043 Iterable<E> expectedElements, 044 int startIndex) { 045 super(steps, elementsToInsert, features, expectedElements, KnownOrder.KNOWN_ORDER, startIndex); 046 } 047 048 @Override 049 protected final Iterable<? extends Stimulus<E, ? super ListIterator<E>>> getStimulusValues() { 050 List<Stimulus<E, ? super ListIterator<E>>> list = new ArrayList<>(); 051 Helpers.addAll(list, iteratorStimuli()); 052 Helpers.addAll(list, listIteratorStimuli()); 053 return list; 054 } 055 056 @Override 057 protected abstract ListIterator<E> newTargetIterator(); 058}