Top Description Fields Constructors Methods
org.assertj.core.api

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

extends AbstractAssert<SELF extends AbstractIteratorAssert<SELF, ELEMENT>, Iterator<? extends ELEMENT>>
Class Inheritance
Known Direct Subclasses
org.assertj.core.api.IteratorAssert
Type Parameters
<SELF>
the "self" type of this assertion class.
<ELEMENT>
the type of elements.
Static Imports
org.assertj.core.error.ShouldBeUnmodifiable.shouldBeUnmodifiable

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().

Author
Stephan Windmüller
Since
3.12.0

Field Summary

Modifier and TypeField and Description
pack-priv Iterators
Inherited from org.assertj.core.api.AbstractAssert:
actualassertionErrorCreatorconditionscustomRepresentationinfomyselfobjectsprintAssertionsDescriptionthrowUnsupportedExceptionOnEquals

Constructor Summary

AccessConstructor and Description
protected
AbstractIteratorAssert(Iterator<? extends ELEMENT>
the actual value to verify
actual
,
Class<?>
the "self type"
selfType
)

Creates a new org.assertj.core.api.AbstractIteratorAssert.

Method Summary

Modifier and TypeMethod and Description
private void
private void
public SELF

Returns:

this assertion object.
hasNext
()

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

public SELF

Returns:

this assertion object.
isExhausted
()

Verifies that the actual Iterator has no more elements.

public SELF

Returns:

this assertion object.
isUnmodifiable
()

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

public IterableAssert<ELEMENT>

Returns:

the new IterableAssert.
toIterable
()

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

Inherited from org.assertj.core.api.AbstractAssert:
areEqualasInstanceOfasListassertionErrorasStringdescribedAsdescriptionTextdoesNotHavedoesNotHaveSameClassAsdoesNotHaveSameHashCodeAsdoesNotHaveToStringdoesNotHaveToStringequalsextractingextractingfailurefailureWithActualExpectedfailWithActualExpectedAndMessagefailWithMessagegetWritableAssertionInfohashashCodehasSameClassAshasSameHashCodeAshasToStringhasToStringinBinaryinHexadecimalisisElementOfCustomAssertisEqualToisExactlyInstanceOfisInisInisInstanceOfisInstanceOfAnyisInstanceOfSatisfyingisNotisNotEqualToisNotExactlyInstanceOfisNotInisNotInisNotInstanceOfisNotInstanceOfAnyisNotNullisNotOfAnyClassInisNotSameAsisNullisOfAnyClassInisSameAsmatchesmatchesnewListAssertInstanceoverridingErrorMessageoverridingErrorMessagesatisfiessatisfiessatisfiessatisfiesAnyOfsatisfiesAnyOfsatisfiesAnyOfForProxysatisfiesForProxysetCustomRepresentationsetDescriptionConsumersetPrintAssertionsDescriptionthrowAssertionErrorusingComparatorusingComparatorusingDefaultComparatorusingRecursiveAssertionusingRecursiveAssertionusingRecursiveComparisonusingRecursiveComparisonwithAssertionStatewithFailMessagewithFailMessagewithRepresentationwithThreadDumpOnError

Field Detail

iteratorsback to summary
pack-priv Iterators iterators
Annotations
@VisibleForTesting

Constructor Detail

AbstractIteratorAssertback to summary
protected AbstractIteratorAssert(Iterator<? extends ELEMENT> actual, Class<?> selfType)

Creates a new org.assertj.core.api.AbstractIteratorAssert.

Parameters
actual:Iterator<? extends ELEMENT>

the actual value to verify

selfType:Class<?>

the "self type"

Method Detail

assertIsUnmodifiableback to summary
private void assertIsUnmodifiable()
expectUnsupportedOperationExceptionback to summary
private void expectUnsupportedOperationException(Runnable runnable, String method)
hasNextback to summary
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:SELF

this assertion object.

Exceptions
AssertionError:
if the actual Iterator is null or does not have another element.
Since
3.12.0
isExhaustedback to summary
public SELF isExhausted()

Verifies that the actual Iterator has no more elements.

Example:
 Iterator<String> result = Collections.emptyList().iterator();

assertThat(result).isExhausted();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
if the actual Iterator is null or has another element.
Since
3.12.0
isUnmodifiableback to summary
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:SELF

this assertion object.

Annotations
@Beta
Exceptions
AssertionError:
if the actual iterator is modifiable.
Since
3.26.0
toIterableback to summary
public IterableAssert<ELEMENT> toIterable()

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

Example:
 Iterator<String> bestBasketBallPlayers = getBestBasketBallPlayers();

assertThat(bestBasketBallPlayers).toIterable().contains("Jordan", "Magic", "Lebron");
Returns:IterableAssert<ELEMENT>

the new IterableAssert.

Since
3.12.0