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 Link icon

    • AbstractIteratorAssert Link icon

      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 Link icon

    • hasNext Link icon

      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 Link icon

      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 Link icon

      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
    • isUnmodifiable Link icon

      public SELF isUnmodifiable()
      Verifies that the actual iterator is unmodifiable, i.e., throws an UnsupportedOperationException with any attempt to remove from the iterator.

      Example:

       // assertions will pass
       assertThat(List.of().iterator()).isUnmodifiable();
       assertThat(Set.of().iterator()).isUnmodifiable();
      
       // assertions will fail
       assertThat(new ArrayList<>().iterator()).isUnmodifiable();
       assertThat(new HashSet<>().iterator()).isUnmodifiable();
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual iterator is modifiable.
      Since:
      3.26.0