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