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; 023import org.checkerframework.checker.nullness.qual.Nullable; 024 025/** 026 * A utility similar to {@link IteratorTester} for testing a {@link ListIterator} against a known 027 * good reference implementation. As with {@code IteratorTester}, a concrete subclass must provide 028 * target iterators on demand. It also requires three additional constructor parameters: {@code 029 * elementsToInsert}, the elements to be passed to {@code set()} and {@code add()} calls; {@code 030 * features}, the features supported by the iterator; and {@code expectedElements}, the elements the 031 * iterator should return in order. 032 * 033 * <p>The items in {@code elementsToInsert} will be repeated if {@code steps} is larger than the 034 * number of provided elements. 035 * 036 * @author Chris Povirk 037 */ 038@GwtCompatible 039@ElementTypesAreNonnullByDefault 040public abstract class ListIteratorTester<E extends @Nullable Object> 041 extends AbstractIteratorTester<E, ListIterator<E>> { 042 protected ListIteratorTester( 043 int steps, 044 Iterable<E> elementsToInsert, 045 Iterable<? extends IteratorFeature> features, 046 Iterable<E> expectedElements, 047 int startIndex) { 048 super(steps, elementsToInsert, features, expectedElements, KnownOrder.KNOWN_ORDER, startIndex); 049 } 050 051 @Override 052 protected final Iterable<? extends Stimulus<E, ? super ListIterator<E>>> getStimulusValues() { 053 List<Stimulus<E, ? super ListIterator<E>>> list = new ArrayList<>(); 054 Helpers.addAll(list, iteratorStimuli()); 055 Helpers.addAll(list, listIteratorStimuli()); 056 return list; 057 } 058 059 @Override 060 protected abstract ListIterator<E> newTargetIterator(); 061}