Class AbstractIteratorAssert<SELF extends AbstractIteratorAssert<SELF,​ELEMENT>,​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 Detail

      • AbstractIteratorAssert

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

      • 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