Top Description Inners Fields Constructors Methods
org.assertj.core.internal

public Class Iterables

extends Object
Class Inheritance
Static Imports
java.util.Arrays.stream, .Objects.requireNonNull, java.util.stream.Collectors.toCollection, .Collectors.toList, org.assertj.core.error.AnyElementShouldMatch.anyElementShouldMatch, .ConditionAndGroupGenericParameterTypeShouldBeTheSame.shouldBeSameGenericBetweenIterableAndCondition, .ElementsShouldBe.elementsShouldBe, .ElementsShouldBeAtLeast.elementsShouldBeAtLeast, .ElementsShouldBeAtMost.elementsShouldBeAtMost, .ElementsShouldBeExactly.elementsShouldBeExactly, .ElementsShouldHave.elementsShouldHave, .ElementsShouldHaveAtLeast.elementsShouldHaveAtLeast, .ElementsShouldHaveAtMost.elementsShouldHaveAtMost, .ElementsShouldHaveExactly.elementsShouldHaveExactly, .ElementsShouldMatch.elementsShouldMatch, .ElementsShouldNotBe.elementsShouldNotBe, .ElementsShouldNotHave.elementsShouldNotHave, .ElementsShouldSatisfy.elementsShouldSatisfy, .ElementsShouldSatisfy.elementsShouldSatisfyAny, .ElementsShouldSatisfy.elementsShouldSatisfyExactly, .NoElementsShouldMatch.noElementsShouldMatch, .NoElementsShouldSatisfy.noElementsShouldSatisfy, .ShouldBeEmpty.shouldBeEmpty, .ShouldBeNullOrEmpty.shouldBeNullOrEmpty, .ShouldBeSubsetOf.shouldBeSubsetOf, .ShouldContain.shouldContain, .ShouldContainAnyOf.shouldContainAnyOf, .ShouldContainExactly.shouldContainExactly, .ShouldContainExactly.shouldContainExactlyWithIndexes, .ShouldContainExactlyInAnyOrder.shouldContainExactlyInAnyOrder, .ShouldContainNull.shouldContainNull, .ShouldContainOnly.shouldContainOnly, .ShouldContainOnlyNulls.shouldContainOnlyNulls, .ShouldContainSequence.shouldContainSequence, .ShouldContainSubsequence.actualDoesNotHaveEnoughElementsToContainSubsequence, .ShouldContainSubsequence.shouldContainSubsequence, .ShouldContainsOnlyOnce.shouldContainsOnlyOnce, .ShouldEndWith.shouldEndWith, .ShouldNotBeEmpty.shouldNotBeEmpty, .ShouldNotContain.shouldNotContain, .ShouldNotContainNull.shouldNotContainNull, .ShouldNotContainSequence.shouldNotContainSequence, .ShouldNotContainSubsequence.shouldNotContainSubsequence, .ShouldNotHaveDuplicates.shouldNotHaveDuplicates, .ShouldSatisfy.shouldSatisfyExactlyInAnyOrder, .ShouldSatisfyOnlyOnce.shouldSatisfyOnlyOnce, .ShouldStartWith.shouldStartWith, .ZippedElementsShouldSatisfy.zippedElementsShouldSatisfy, org.assertj.core.internal.Arrays.assertIsArray, .CommonValidations.checkIsNotNull, .CommonValidations.checkIsNotNullAndNotEmpty, .CommonValidations.checkIterableIsNotNull, .CommonValidations.checkSizeBetween, .CommonValidations.checkSizeGreaterThan, .CommonValidations.checkSizeGreaterThanOrEqualTo, .CommonValidations.checkSizeLessThan, .CommonValidations.checkSizeLessThanOrEqualTo, .CommonValidations.checkSizes, .CommonValidations.failIfEmptySinceActualIsNotEmpty, .CommonValidations.hasSameSizeAsCheck, .ErrorMessages.emptySequence, .ErrorMessages.emptySubsequence, .ErrorMessages.nullSequence, .ErrorMessages.nullSubsequence, .IterableDiff.diff, org.assertj.core.util.Arrays.asList, .Arrays.prepend, .IterableUtil.isNullOrEmpty, .IterableUtil.sizeOf, .Lists.list, .Lists.newArrayList, .Streams.stream

Reusable assertions for Iterables.
Authors
Alex Ruiz, Yvonne Wang, Maciej Jaskowski, Nicolas François, Joel Costigliola, Florent Biville

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final ComparisonStrategy
pack-priv Conditions
pack-priv Failures
private static final Iterables
pack-priv Predicates

Constructor Summary

AccessConstructor and Description
pack-priv
public
Iterables(ComparisonStrategy comparisonStrategy)

Method Summary

Modifier and TypeMethod and Description
private AssertionError
actualContainsSubsequence(AssertionInfo info, Iterable<?> actual, Object[] subsequence, int index)

private AssertionError
actualDoesContainSequence(AssertionInfo info, Iterable<?> actual, Object[] sequence, int index)

private AssertionError
private AssertionError
actualDoesNotContainSubsequence(AssertionInfo info, Iterable<?> actual, Object[] subsequence, int subsequenceIndex)

private AssertionError
private AssertionError
private static <E> boolean
areAllConsumersSatisfied(Queue<ElementsSatisfyingConsumer<E>> satisfiedElementsPerConsumer)

private boolean
areEqual(Object actual, Object other)

public <E> void
assertAllMatch(AssertionInfo info, Iterable<? extends E> actual, Predicate<? super E> predicate, PredicateDescription predicateDescription)

public <E> void
assertAllSatisfy(AssertionInfo info, Iterable<? extends E> actual, Consumer<? super E> requirements)

public <E> void
assertAnyMatch(AssertionInfo info, Iterable<? extends E> actual, Predicate<? super E> predicate, PredicateDescription predicateDescription)

public <E> void
assertAnySatisfy(AssertionInfo info, Iterable<? extends E> actual, Consumer<? super E> requirements)

public <
the type of actual elements
T
>
void
assertAre(AssertionInfo
contains information about the assertion.
info
,
Iterable<? extends T>
the given Iterable.
actual
,
Condition<? super T>
the given Condition.
condition
)

Assert that each element of given Iterable satisfies the given condition.

public <
the type of actual elements
E
>
void
assertAreAtLeast(AssertionInfo
contains information about the assertion.
info
,
Iterable<? extends E>
the given Iterable.
actual
,
int
the minimum number of times the condition should be verified.
times
,
Condition<? super E>
the given Condition.
condition
)

Assert that there are at least n elements in the actual Iterable satisfying the given condition.

public <
the type of actual elements
E
>
void
assertAreAtMost(AssertionInfo
contains information about the assertion.
info
,
Iterable<? extends E>
the given Iterable.
actual
,
int
the number of times the condition should be at most verified.
n
,
Condition<? super E>
the given Condition.
condition
)

Assert that there are at most n elements in the actual Iterable satisfying the given condition.

public <
the type of actual elements
E
>
void
assertAreExactly(AssertionInfo
contains information about the assertion.
info
,
Iterable<? extends E>
the given Iterable.
actual
,
int
the exact number of times the condition should be verified.
times
,
Condition<? super E>
the given Condition.
condition
)

Verifies that there are exactly n elements in the actual Iterable satisfying the given condition.

public <
the type of actual elements
E
>
void
assertAreNot(AssertionInfo
contains information about the assertion.
info
,
Iterable<? extends E>
the given Iterable.
actual
,
Condition<? super E>
the given Condition.
condition
)

Assert that each element of given Iterable not satisfies the given condition.

public void
assertContains(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object[]
the values that are expected to be in the given Iterable.
values
)

Asserts that the given Iterable contains the given values, in any order.

public void
assertContainsAll(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Iterable<?>
the other Iterable.
other
)

Asserts that the given Iterable contains all the elements of the other Iterable, in any order.

public void
assertContainsAnyOf(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object[]
the values that, at least one of which is expected to be in the given Iterable.
values
)

Asserts that the given Iterable contains at least one of the given values.

public void
assertContainsExactly(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object[]
the values that are expected to be in the given Iterable in order.
values
)

Asserts that the given Iterable contains exactly the given values and nothing else, in order.

public void
public void
assertContainsNull(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
)

Asserts that the given Iterable contains at least a null element.

public void
assertContainsOnly(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object[]
the values that are expected to be in the given Iterable.
expectedValues
)

Asserts that the given Iterable contains only the given values and nothing else, in any order.

public void
assertContainsOnlyNulls(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
)

Asserts that the given Iterable contains only null elements and nothing else.

public void
assertContainsOnlyOnce(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object[]
the values that are expected to be in the given Iterable.
values
)

Asserts that the given Iterable contains the given values and only once.

public void
assertContainsSequence(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object[]
the sequence of objects to look for.
sequence
)

Verifies that the given Iterable contains the given sequence of objects, without any other objects between them.

public void
assertContainsSubsequence(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object[]
the subsequence of objects to look for.
subsequence
)

Verifies that the given Iterable contains the given subsequence of objects (possibly with other values between them).

public void
assertDoesNotContain(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object[]
the values that are expected not to be in the given Iterable.
values
)

Asserts that the given Iterable does not contain the given values.

public <
the type of actual elements
T
>
void
assertDoesNotContainAnyElementsOf(AssertionInfo
contains information about the assertion.
info
,
Iterable<? extends T>
the given Iterable.
actual
,
Iterable<? extends T>
the values that are expected not to be in the given Iterable.
iterable
)

Asserts that the given Iterable does not contain the given values.

public void
assertDoesNotContainNull(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
)

Asserts that the given Iterable does not contain null elements.

public void
assertDoesNotContainSequence(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object[]
the sequence of objects to look for.
sequence
)

Verifies that the given Iterable does not contain the given sequence of objects in order.

public void
assertDoesNotContainSubsequence(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object[]
the subsequence of objects to look for.
subsequence
)

Verifies that the given Iterable does not contain the given subsequence of objects (possibly with other values between them).

public void
assertDoesNotHaveDuplicates(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
)

Asserts that the given Iterable does not have duplicate values.

public <
the type of actual elements
E
>
void
assertDoNotHave(AssertionInfo
contains information about the assertion.
info
,
Iterable<? extends E>
the given Iterable.
actual
,
Condition<? super E>
the given Condition.
condition
)

Assert that each element of given Iterable not satisfies the given condition.

private void
assertElementOrder(AssertionInfo info, Iterable<?> actual, Object[] values, List<Object> actualAsList)

public void
assertEmpty(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
)

Asserts that the given Iterable is empty.

public void
assertEndsWith(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object
the first element of the end sequence.
first
,
Object[]
the optional next elements of the end sequence.
rest
)

Verifies that the given Iterable ends with the given sequence of objects, without any other objects between them.

public void
assertEndsWith(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object[]
the sequence of objects to look for.
sequence
)

Verifies that the given Iterable ends with the given sequence of objects, without any other objects between them.

private void
assertEquivalency(AssertionInfo info, Iterable<?> actual, Object[] values, List<Object> actualAsList)

public <
the type of elements in actual.
T
>
void
assertHasOnlyOneElementSatisfying(AssertionInfo
contains information about the assertion.
info
,
Iterable<? extends T>
the given Iterable.
actual
,
Consumer<? super T>
the given requirements.
consumer
)

Asserts that the unique element of the Iterable satisfies the given assertions expressed as a Consumer,

public void
assertHasSameSizeAs(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object
the given array to compare.
other
)

Assert that the actual Iterable has the same size as the other array.

public void
assertHasSameSizeAs(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Iterable<?>
the given Iterable.
other
)

Assert that the actual Iterable has the same size as the other Iterable.

public void
assertHasSize(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
int
the expected size of actual.
expectedSize
)

Asserts that the number of elements in the given Iterable is equal to the expected one.

public void
assertHasSizeBetween(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
int
the lower boundary compared to which actual size should be greater than or equal to.
lowerBoundary
,
int
the higher boundary compared to which actual size should be less than or equal to.
higherBoundary
)

Asserts that the number of elements in the given Iterable is between the given lower and higher boundary (inclusive).

public void
assertHasSizeGreaterThan(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
int
the given value to compare the size of actual to.
boundary
)

Asserts that the number of elements in the given Iterable is greater than the boundary.

public void
assertHasSizeGreaterThanOrEqualTo(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
int
the given value to compare the size of actual to.
boundary
)

Asserts that the number of elements in the given Iterable is greater than or equal to the boundary.

public void
assertHasSizeLessThan(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
int
the given value to compare the size of actual to.
boundary
)

Asserts that the number of elements in the given Iterable is less than the boundary.

public void
assertHasSizeLessThanOrEqualTo(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
int
the given value to compare the size of actual to.
boundary
)

Asserts that the number of elements in the given Iterable is less than or equal to the boundary.

public <
the type of actual elements
E
>
void
assertHave(AssertionInfo
contains information about the assertion.
info
,
Iterable<? extends E>
the given Iterable.
actual
,
Condition<? super E>
the given Condition.
condition
)

Assert that each element of given Iterable satisfies the given condition.

public <
the type of actual elements
E
>
void
assertHaveAtLeast(AssertionInfo
contains information about the assertion.
info
,
Iterable<? extends E>
the given Iterable.
actual
,
int
the minimum number of times the condition should be verified.
times
,
Condition<? super E>
the given Condition.
condition
)

An alias method of assertAreAtLeast(AssertionInfo, Iterable, int, Condition) to provide a richer fluent api (same logic, only error message differs).

public <
the type of actual elements
E
>
void
assertHaveAtMost(AssertionInfo
contains information about the assertion.
info
,
Iterable<? extends E>
the given Iterable.
actual
,
int
the number of times the condition should be at most verified.
times
,
Condition<? super E>
the given Condition.
condition
)

An alias method of assertAreAtMost(AssertionInfo, Iterable, int, Condition) to provide a richer fluent api (same logic, only error message differs).

public <
the type of actual elements
E
>
void
assertHaveExactly(AssertionInfo
contains information about the assertion.
info
,
Iterable<? extends E>
the given Iterable.
actual
,
int
the exact number of times the condition should be verified.
times
,
Condition<? super E>
the given Condition.
condition
)

An alias method of assertAreExactly(AssertionInfo, Iterable, int, Condition) to provide a richer fluent api (same logic, only error message differs).

public void
assertIsSubsetOf(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the actual Iterable.
actual
,
Iterable<?>
the Iterable that should contain all actual elements.
values
)

Verifies that the actual Iterable is a subset of values Iterable.

private void
assertIterableContainsGivenValues(Class<? extends Iterable<T>> clazz, Iterable<?> actual, Object[] values, AssertionInfo info)

public <E> void
assertNoneMatch(AssertionInfo info, Iterable<? extends E> actual, Predicate<? super E> predicate, PredicateDescription predicateDescription)

public <E> void
assertNoneSatisfy(AssertionInfo info, Iterable<? extends E> actual, Consumer<? super E> restrictions)

public void
assertNotEmpty(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
)

Asserts that the given Iterable is not empty.

pack-priv void
public void
assertNullOrEmpty(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
)

Asserts that the given Iterable is null or empty.

public <E> void
assertSatisfiesExactly(AssertionInfo info, Iterable<? extends E> actual, Consumer<? super E>[] allRequirements)

public <E> void
assertSatisfiesExactlyInAnyOrder(AssertionInfo info, Iterable<? extends E> actual, Consumer<? super E>[] consumers)

public <E> void
assertSatisfiesOnlyOnce(AssertionInfo info, Iterable<? extends E> actual, Consumer<? super E> requirements)

public void
assertStartsWith(AssertionInfo
contains information about the assertion.
info
,
Iterable<?>
the given Iterable.
actual
,
Object[]
the sequence of objects to look for.
sequence
)

Verifies that the given Iterable starts with the given sequence of objects, without any other objects between them.

public <ACTUAL_ELEMENT, OTHER_ELEMENT> void
assertZipSatisfy(AssertionInfo info, Iterable<? extends ACTUAL_ELEMENT> actual, Iterable<OTHER_ELEMENT> other, BiConsumer<? super ACTUAL_ELEMENT, OTHER_ELEMENT> zipRequirements)

public static <T> Predicate<T>
byPassingAssertions(Consumer<? super T> assertions)

private static void
private static void
private void
checkNotNullIterables(AssertionInfo info, Iterable<?> actual, Object[] sequence)

private boolean
private List<IndexedDiff>
compareOrder(Object[] values, List<Object> actualAsList)

private <E> boolean
conditionIsSatisfiedAtLeastNTimes(Iterable<? extends E> actual, int n, Condition<? super E> condition)

private <E> boolean
conditionIsSatisfiedAtMostNTimes(Iterable<? extends E> actual, Condition<? super E> condition, int n)

private <E> boolean
conditionIsSatisfiedNTimes(Iterable<? extends E> actual, Condition<? super E> condition, int times)

private boolean

Returns:

true if actualAsList contains exactly the given sequence at given starting index, false otherwise.
containsSequenceAtGivenIndex
(List<?>
the list to look sequence in
actualAsList
,
Object[]
the sequence to look for
sequence
,
int
the index of actual list at which we start looking for sequence.
startingIndex
)

Return true if actualAsList contains exactly the given sequence at given starting index, false otherwise.

private static Collection<?>
private static <E> Optional<UnsatisfiedRequirement>
failsRequirements(Consumer<? super E> requirements, E element)

private <E> Optional<E>
failsRestrictions(E element, Consumer<? super E> restrictions)

private <ACTUAL_ELEMENT, OTHER_ELEMENT> Optional<ZippedElementsShouldSatisfy.ZipSatisfyError>
failsZipRequirements(ACTUAL_ELEMENT actualElement, OTHER_ELEMENT otherElement, BiConsumer<ACTUAL_ELEMENT, OTHER_ELEMENT> zipRequirements)

public Comparator<?>
public ComparisonStrategy
public static Iterables

Returns:

the singleton instance of this class based on StandardComparisonStrategy.
instance
()

Returns the singleton instance of this class based on StandardComparisonStrategy.

private boolean
iterableContains(Iterable<?> actual, Object value)

private void
iterablesRemove(Iterable<?> actual, Object value)

private void
private <E> List<E>
notSatisfyingCondition(Iterable<? extends E> actual, Condition<? super E> condition)

private static <E> Queue<ElementsSatisfyingConsumer<E>>
removeElement(Queue<ElementsSatisfyingConsumer<E>> satisfiedElementsPerConsumer, E element)

private static <E> Deque<ElementsSatisfyingConsumer<E>>
satisfiedElementsPerConsumer(Iterable<? extends E> actual, Consumer<? super E>... consumers)

private <E> List<E>
satisfiesCondition(Iterable<? extends E> actual, Condition<? super E> condition)

private AssertionError
private AssertionError
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait