Class AbstractIteratorAssert<SELF extends AbstractIteratorAssert<SELF,ELEMENT>,ELEMENT>

java.lang.Object
org.assertj.core.api.AbstractAssert<SELF,Iterator<? extends ELEMENT>>
org.assertj.core.api.AbstractIteratorAssert<SELF,ELEMENT>
Type Parameters:
SELF - the "self" type of this assertion class.
ELEMENT - the type of elements.
All Implemented Interfaces:
Assert<SELF,Iterator<? extends ELEMENT>>, Descriptable<SELF>, ExtensionPoints<SELF,Iterator<? extends ELEMENT>>
Direct Known Subclasses:
IteratorAssert

public abstract class AbstractIteratorAssert<SELF extends AbstractIteratorAssert<SELF,ELEMENT>,ELEMENT> extends AbstractAssert<SELF,Iterator<? extends ELEMENT>>

Base class for all implementations of assertions for Iterators.

Note that none of the assertions modify the actual iterator, i.e. they do not consume any elements. In order to use consuming assertions, use toIterable().

Since:
3.12.0
Author:
Stephan Windmüller
  • Constructor Details

    • AbstractIteratorAssert

      protected AbstractIteratorAssert(Iterator<? extends ELEMENT> actual, Class<?> selfType)
      Creates a new AbstractIteratorAssert.
      Parameters:
      actual - the actual value to verify
      selfType - the "self type"
  • Method Details

    • hasNext

      public SELF hasNext()

      Verifies that the actual Iterator has at least one more element.

      Example:
       Iterator<TolkienCharacter> elvesRingBearers = list(galadriel, elrond, gandalf).iterator();
      
       assertThat(elvesRingBearers).hasNext();
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual Iterator is null or does not have another element.
      Since:
      3.12.0
    • isExhausted

      public SELF isExhausted()

      Verifies that the actual Iterator has no more elements.

      Example:
       Iterator<String> result = Collections.emptyList().iterator();
      
       assertThat(result).isExhausted();
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual Iterator is null or has another element.
      Since:
      3.12.0
    • toIterable

      public IterableAssert<ELEMENT> toIterable()

      Creates a new IterableAssert from this IteratorAssert which allows for using any Iterable assertions like AbstractIterableAssert.contains(Object[]).

      Example:
       Iterator<String> bestBasketBallPlayers = getBestBasketBallPlayers();
      
       assertThat(bestBasketBallPlayers).toIterable().contains("Jordan", "Magic", "Lebron");
      Returns:
      the new IterableAssert.
      Since:
      3.12.0