Package org.fest.assertions.internal
Class Iterables
- java.lang.Object
-
- org.fest.assertions.internal.Iterables
-
public class Iterables extends java.lang.ObjectReusable assertions fors.Iterable- Author:
- Alex Ruiz, Yvonne Wang, Maciej Jaskowski, Nicolas François, Joel Costigliola
-
-
Constructor Summary
Constructors Constructor Description Iterables(ComparisonStrategy comparisonStrategy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <E> voidassertAre(AssertionInfo info, java.lang.Iterable<? extends E> actual, Condition<? super E> condition)Assert that each element of givenIterablesatisfies the given condition.<E> voidassertAreAtLeast(AssertionInfo info, java.lang.Iterable<? extends E> actual, int n, Condition<? super E> condition)Assert that there is at least n elements in the actualIterablesatisfying the given condition.<E> voidassertAreAtMost(AssertionInfo info, java.lang.Iterable<? extends E> actual, int n, Condition<? super E> condition)Assert that there is at most n elements in the actualIterablesatisfying the given condition.<E> voidassertAreExactly(AssertionInfo info, java.lang.Iterable<? extends E> actual, int n, Condition<? super E> condition)Verifies that there is exactly n elements in the actualIterablesatisfying the given condition.<E> voidassertAreNot(AssertionInfo info, java.lang.Iterable<? extends E> actual, Condition<? super E> condition)Assert that each element of givenIterablenot satisfies the given condition.<E> voidassertAreNotAtLeast(AssertionInfo info, java.lang.Iterable<? extends E> actual, int n, Condition<? super E> condition)Assert that there is at least n elements in the actualIterablenot satisfying the given condition.<E> voidassertAreNotAtMost(AssertionInfo info, java.lang.Iterable<? extends E> actual, int n, Condition<? super E> condition)Verifies that there is at most n elements in the actualIterablenot satisfying the given condition.<E> voidassertAreNotExactly(AssertionInfo info, java.lang.Iterable<? extends E> actual, int n, Condition<? super E> condition)Verifies that there is exactly n elements in the actualIterablenot satisfying the given condition.voidassertContains(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] values)Asserts that the givenIterablecontains the given values, in any order.voidassertContainsAll(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Iterable<?> other)Asserts that the givenIterablecontains all the elements of the otherIterable, in any order.voidassertContainsExactly(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] values)Asserts that the givenIterablecontains exactly the given values and nothing else, in order.voidassertContainsNull(AssertionInfo info, java.lang.Iterable<?> actual)Asserts that the givenIterablecontains at least a null element.voidassertContainsOnly(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] values)Asserts that the givenIterablecontains only the given values and nothing else, in any order.voidassertContainsSequence(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] sequence)Verifies that the givencontains the given sequence of objects, without any other objects between them.IterablevoidassertDoesNotContain(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] values)Asserts that the givenIterabledoes not contain the given values.voidassertDoesNotContainNull(AssertionInfo info, java.lang.Iterable<?> actual)Asserts that the givenIterabledoes not contain null elements.voidassertDoesNotHaveDuplicates(AssertionInfo info, java.lang.Iterable<?> actual)Asserts that the givenIterabledoes not have duplicate values.<E> voidassertDoNotHave(AssertionInfo info, java.lang.Iterable<? extends E> actual, Condition<? super E> condition)Assert that each element of givenIterablenot satisfies the given condition.<E> voidassertDoNotHaveAtLeast(AssertionInfo info, java.lang.Iterable<? extends E> actual, int times, Condition<? super E> condition)An alias method ofassertAreNotAtLeast(AssertionInfo, Iterable, int, Condition)to provide a richer fluent api (same logic, only error message differs).<E> voidassertDoNotHaveAtMost(AssertionInfo info, java.lang.Iterable<? extends E> actual, int times, Condition<? super E> condition)An alias method ofassertAreNotAtMost(AssertionInfo, Iterable, int, Condition)to provide a richer fluent api (same logic, only error message differs).<E> voidassertDoNotHaveExactly(AssertionInfo info, java.lang.Iterable<? extends E> actual, int times, Condition<? super E> condition)An alias method ofassertAreNotExactly(AssertionInfo, Iterable, int, Condition)to provide a richer fluent api (same logic, only error message differs).voidassertEmpty(AssertionInfo info, java.lang.Iterable<?> actual)Asserts that the givenIterableis empty.voidassertEndsWith(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] sequence)Verifies that the givenIterableends with the given sequence of objects, without any other objects between them.voidassertHasSameSizeAs(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Iterable<?> other)Assert that the actualIterablehas the same size as the otherIterable.voidassertHasSameSizeAs(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] other)Assert that the actualIterablehas the same size as the other array.voidassertHasSize(AssertionInfo info, java.lang.Iterable<?> actual, int expectedSize)Asserts that the number of elements in the givenIterableis equal to the expected one.<E> voidassertHave(AssertionInfo info, java.lang.Iterable<? extends E> actual, Condition<? super E> condition)Assert that each element of givenIterablesatisfies the given condition.<E> voidassertHaveAtLeast(AssertionInfo info, java.lang.Iterable<? extends E> actual, int times, Condition<? super E> condition)An alias method ofassertAreAtLeast(AssertionInfo, Iterable, int, Condition)to provide a richer fluent api (same logic, only error message differs).<E> voidassertHaveAtMost(AssertionInfo info, java.lang.Iterable<? extends E> actual, int times, Condition<? super E> condition)An alias method ofassertAreAtMost(AssertionInfo, Iterable, int, Condition)to provide a richer fluent api (same logic, only error message differs).<E> voidassertHaveExactly(AssertionInfo info, java.lang.Iterable<? extends E> actual, int times, Condition<? super E> condition)An alias method ofassertAreExactly(AssertionInfo, Iterable, int, Condition)to provide a richer fluent api (same logic, only error message differs).voidassertIsSubsetOf(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Iterable<?> values)Verifies that the actualIterableis a subset of valuesIterable.voidassertNotEmpty(AssertionInfo info, java.lang.Iterable<?> actual)Asserts that the givenIterableis not empty.voidassertNullOrEmpty(AssertionInfo info, java.lang.Iterable<?> actual)Asserts that the givenisIterablenullor empty.voidassertStartsWith(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] sequence)Verifies that the givenIterablestarts with the given sequence of objects, without any other objects between them.java.util.Comparator<?>getComparator()static Iterablesinstance()Returns the singleton instance of this class based onStandardComparisonStrategy.static java.lang.IllegalArgumentExceptioniterableToLookForIsEmpty()static java.lang.NullPointerExceptioniterableToLookForIsNull()
-
-
-
Constructor Detail
-
Iterables
public Iterables(ComparisonStrategy comparisonStrategy)
-
-
Method Detail
-
instance
public static Iterables instance()
Returns the singleton instance of this class based onStandardComparisonStrategy.- Returns:
- the singleton instance of this class based on
StandardComparisonStrategy.
-
getComparator
public java.util.Comparator<?> getComparator()
-
assertNullOrEmpty
public void assertNullOrEmpty(AssertionInfo info, java.lang.Iterable<?> actual)
Asserts that the givenisIterablenullor empty.- Parameters:
info- contains information about the assertion.actual- the givenIterable.- Throws:
java.lang.AssertionError- if the givenIterableis notnull*and* contains one or more elements.
-
assertEmpty
public void assertEmpty(AssertionInfo info, java.lang.Iterable<?> actual)
Asserts that the givenIterableis empty.- Parameters:
info- contains information about the assertion.actual- the givenIterable.- Throws:
java.lang.AssertionError- if the givenIterableisnull.java.lang.AssertionError- if the givenIterableis not empty.
-
assertNotEmpty
public void assertNotEmpty(AssertionInfo info, java.lang.Iterable<?> actual)
Asserts that the givenIterableis not empty.- Parameters:
info- contains information about the assertion.actual- the givenIterable.- Throws:
java.lang.AssertionError- if the givenIterableisnull.java.lang.AssertionError- if the givenIterableis empty.
-
assertHasSize
public void assertHasSize(AssertionInfo info, java.lang.Iterable<?> actual, int expectedSize)
Asserts that the number of elements in the givenIterableis equal to the expected one.- Parameters:
info- contains information about the assertion.actual- the givenIterable.expectedSize- the expected size ofactual.- Throws:
java.lang.AssertionError- if the givenIterableisnull.java.lang.AssertionError- if the number of elements in the givenIterableis different than the expected one.
-
assertHasSameSizeAs
public void assertHasSameSizeAs(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] other)
Assert that the actualIterablehas the same size as the other array.- Parameters:
info- contains information about the assertion.actual- the givenIterable.other- the given array to compare.- Throws:
java.lang.AssertionError- if the actual group isnull.java.lang.AssertionError- if the other group isnull.java.lang.AssertionError- if actualIterableand other array don't have the same size.
-
assertHasSameSizeAs
public void assertHasSameSizeAs(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Iterable<?> other)
Assert that the actualIterablehas the same size as the otherIterable.- Parameters:
info- contains information about the assertion.actual- the givenIterable.other- the givenIterable.- Throws:
java.lang.AssertionError- if the actual group isnull.java.lang.AssertionError- if the other group isnull.java.lang.AssertionError- if actual and otherIterabledon't have the same size.
-
assertContains
public void assertContains(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] values)
Asserts that the givenIterablecontains the given values, in any order.- Parameters:
info- contains information about the assertion.actual- the givenIterable.values- the values that are expected to be in the givenIterable.- Throws:
java.lang.NullPointerException- if the array of values isnull.java.lang.IllegalArgumentException- if the array of values is empty.java.lang.AssertionError- if the givenIterableisnull.java.lang.AssertionError- if the givenIterabledoes not contain the given values.
-
assertContainsOnly
public void assertContainsOnly(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] values)
Asserts that the givenIterablecontains only the given values and nothing else, in any order.- Parameters:
info- contains information about the assertion.actual- the givenIterable.values- the values that are expected to be in the givenIterable.- Throws:
java.lang.NullPointerException- if the array of values isnull.java.lang.IllegalArgumentException- if the array of values is empty.java.lang.AssertionError- if the givenIterableisnull.java.lang.AssertionError- if the givenIterabledoes not contain the given values or if the givenIterablecontains values that are not in the given array.
-
assertContainsSequence
public void assertContainsSequence(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] sequence)
Verifies that the givencontains the given sequence of objects, without any other objects between them.Iterable- Parameters:
info- contains information about the assertion.actual- the givenIterable.sequence- the sequence of objects to look for.- Throws:
java.lang.AssertionError- if the givenIterableisnull.java.lang.NullPointerException- if the given sequence isnull.java.lang.IllegalArgumentException- if the given sequence is empty.java.lang.AssertionError- if the givenIterabledoes not contain the given sequence of objects.
-
assertIsSubsetOf
public void assertIsSubsetOf(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Iterable<?> values)
Verifies that the actualIterableis a subset of valuesIterable.
Both actual and given iterable are treated as sets, therefore duplicates on either of them are ignored.- Parameters:
info- contains information about the assertion.actual- the actualIterable.values- theIterablethat should contain all actual elements.- Throws:
java.lang.AssertionError- if the actualIterableisnull.java.lang.NullPointerException- if the given Iterable isnull.java.lang.AssertionError- if the actualIterableis not subset of setIterable
-
assertDoesNotContain
public void assertDoesNotContain(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] values)
Asserts that the givenIterabledoes not contain the given values.- Parameters:
info- contains information about the assertion.actual- the givenIterable.values- the values that are expected not to be in the givenIterable.- Throws:
java.lang.NullPointerException- if the array of values isnull.java.lang.IllegalArgumentException- if the array of values is empty.java.lang.AssertionError- if the givenIterableisnull.java.lang.AssertionError- if the givenIterablecontains any of given values.
-
assertDoesNotHaveDuplicates
public void assertDoesNotHaveDuplicates(AssertionInfo info, java.lang.Iterable<?> actual)
Asserts that the givenIterabledoes not have duplicate values.- Parameters:
info- contains information about the assertion.actual- the givenIterable.- Throws:
java.lang.NullPointerException- if the array of values isnull.java.lang.IllegalArgumentException- if the array of values is empty.java.lang.AssertionError- if the givenIterableisnull.java.lang.AssertionError- if the givenIterablecontains duplicate values.
-
assertStartsWith
public void assertStartsWith(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] sequence)
Verifies that the givenIterablestarts with the given sequence of objects, without any other objects between them. Similar to, but it also verifies that the first element in the sequence is also the first element of the givenassertContainsSequence(AssertionInfo, Iterable, Object[])Iterable.- Parameters:
info- contains information about the assertion.actual- the givenIterable.sequence- the sequence of objects to look for.- Throws:
java.lang.NullPointerException- if the given argument isnull.java.lang.IllegalArgumentException- if the given argument is an empty array.java.lang.AssertionError- if the givenIterableisnull.java.lang.AssertionError- if the givenIterabledoes not start with the given sequence of objects.
-
assertEndsWith
public void assertEndsWith(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] sequence)
Verifies that the givenIterableends with the given sequence of objects, without any other objects between them. Similar to, but it also verifies that the last element in the sequence is also the last element of the givenassertContainsSequence(AssertionInfo, Iterable, Object[])Iterable.- Parameters:
info- contains information about the assertion.actual- the givenIterable.sequence- the sequence of objects to look for.- Throws:
java.lang.NullPointerException- if the given argument isnull.java.lang.IllegalArgumentException- if the given argument is an empty array.java.lang.AssertionError- if the givenIterableisnull.java.lang.AssertionError- if the givenIterabledoes not end with the given sequence of objects.
-
assertContainsNull
public void assertContainsNull(AssertionInfo info, java.lang.Iterable<?> actual)
Asserts that the givenIterablecontains at least a null element.- Parameters:
info- contains information about the assertion.actual- the givenIterable.- Throws:
java.lang.AssertionError- if the givenIterableisnull.java.lang.AssertionError- if the givenIterabledoes not contain at least a null element.
-
assertDoesNotContainNull
public void assertDoesNotContainNull(AssertionInfo info, java.lang.Iterable<?> actual)
Asserts that the givenIterabledoes not contain null elements.- Parameters:
info- contains information about the assertion.actual- the givenIterable.- Throws:
java.lang.AssertionError- if the givenIterableisnull.java.lang.AssertionError- if the givenIterablecontains a null element.
-
assertAre
public <E> void assertAre(AssertionInfo info, java.lang.Iterable<? extends E> actual, Condition<? super E> condition)
Assert that each element of givenIterablesatisfies the given condition.- Parameters:
info- contains information about the assertion.actual- the givenIterable.condition- the givenCondition.- Throws:
java.lang.NullPointerException- if the given condition isnull.java.lang.AssertionError- if a element cannot be cast to E.java.lang.AssertionError- if one or more element not satisfy the given condition.
-
assertAreNot
public <E> void assertAreNot(AssertionInfo info, java.lang.Iterable<? extends E> actual, Condition<? super E> condition)
Assert that each element of givenIterablenot satisfies the given condition.- Parameters:
info- contains information about the assertion.actual- the givenIterable.condition- the givenCondition.- Throws:
java.lang.NullPointerException- if the given condition isnull.java.lang.AssertionError- if a element cannot be cast to E.java.lang.AssertionError- if one or more element satisfy the given condition.
-
assertHave
public <E> void assertHave(AssertionInfo info, java.lang.Iterable<? extends E> actual, Condition<? super E> condition)
Assert that each element of givenIterablesatisfies the given condition.- Parameters:
info- contains information about the assertion.actual- the givenIterable.condition- the givenCondition.- Throws:
java.lang.NullPointerException- if the given condition isnull.java.lang.AssertionError- if a element cannot be cast to E.java.lang.AssertionError- if one or more element not satisfy the given condition.
-
assertDoNotHave
public <E> void assertDoNotHave(AssertionInfo info, java.lang.Iterable<? extends E> actual, Condition<? super E> condition)
Assert that each element of givenIterablenot satisfies the given condition.- Parameters:
info- contains information about the assertion.actual- the givenIterable.condition- the givenCondition.- Throws:
java.lang.NullPointerException- if the given condition isnull.java.lang.AssertionError- if a element cannot be cast to E.java.lang.AssertionError- if one or more element satisfy the given condition.
-
assertAreAtLeast
public <E> void assertAreAtLeast(AssertionInfo info, java.lang.Iterable<? extends E> actual, int n, Condition<? super E> condition)
Assert that there is at least n elements in the actualIterablesatisfying the given condition.- Parameters:
info- contains information about the assertion.actual- the givenIterable.n- the minimum number of times the condition should be verified.condition- the givenCondition.- Throws:
java.lang.NullPointerException- if the given condition isnull.java.lang.AssertionError- if a element cannot be cast to E.java.lang.AssertionError- if the number of elements satisfying the given condition is < n.
-
assertAreNotAtLeast
public <E> void assertAreNotAtLeast(AssertionInfo info, java.lang.Iterable<? extends E> actual, int n, Condition<? super E> condition)
Assert that there is at least n elements in the actualIterablenot satisfying the given condition.- Parameters:
info- contains information about the assertion.actual- the givenIterable.n- the number of times the condition should not be verified at least.condition- the givenCondition.- Throws:
java.lang.NullPointerException- if the given condition isnull.java.lang.AssertionError- if a element cannot be cast to E.java.lang.AssertionError- if the number of elements not satisfying the given condition is < n.
-
assertAreAtMost
public <E> void assertAreAtMost(AssertionInfo info, java.lang.Iterable<? extends E> actual, int n, Condition<? super E> condition)
Assert that there is at most n elements in the actualIterablesatisfying the given condition.- Parameters:
info- contains information about the assertion.actual- the givenIterable.n- the number of times the condition should be at most verified.condition- the givenCondition.- Throws:
java.lang.NullPointerException- if the given condition isnull.java.lang.AssertionError- if a element cannot be cast to E.java.lang.AssertionError- if the number of elements satisfying the given condition is > n.
-
assertAreNotAtMost
public <E> void assertAreNotAtMost(AssertionInfo info, java.lang.Iterable<? extends E> actual, int n, Condition<? super E> condition)
Verifies that there is at most n elements in the actualIterablenot satisfying the given condition.- Parameters:
info- contains information about the assertion.actual- the givenIterable.n- the number of times the condition should not be verified at most.condition- the givenCondition.- Throws:
java.lang.NullPointerException- if the given condition isnull.java.lang.AssertionError- if a element cannot be cast to E.java.lang.AssertionError- if the number of elements not satisfying the given condition is > n.
-
assertAreExactly
public <E> void assertAreExactly(AssertionInfo info, java.lang.Iterable<? extends E> actual, int n, Condition<? super E> condition)
Verifies that there is exactly n elements in the actualIterablesatisfying the given condition.- Parameters:
info- contains information about the assertion.actual- the givenIterable.n- the exact number of times the condition should be verified.condition- the givenCondition.- Throws:
java.lang.NullPointerException- if the given condition isnull.java.lang.AssertionError- if a element cannot be cast to E.java.lang.AssertionError- if the number of elements satisfying the given condition is ≠ n.
-
assertAreNotExactly
public <E> void assertAreNotExactly(AssertionInfo info, java.lang.Iterable<? extends E> actual, int n, Condition<? super E> condition)
Verifies that there is exactly n elements in the actualIterablenot satisfying the given condition.- Parameters:
info- contains information about the assertion.actual- the givenIterable.n- the exact number of times the condition should not be verified.condition- the givenCondition.- Throws:
java.lang.NullPointerException- if the given condition isnull.java.lang.AssertionError- if a element cannot be cast to E.java.lang.AssertionError- if the number of elements not satisfying the given condition is ≠ n.
-
assertHaveAtLeast
public <E> void assertHaveAtLeast(AssertionInfo info, java.lang.Iterable<? extends E> actual, int times, Condition<? super E> condition)
An alias method ofassertAreAtLeast(AssertionInfo, Iterable, int, Condition)to provide a richer fluent api (same logic, only error message differs).
-
assertDoNotHaveAtLeast
public <E> void assertDoNotHaveAtLeast(AssertionInfo info, java.lang.Iterable<? extends E> actual, int times, Condition<? super E> condition)
An alias method ofassertAreNotAtLeast(AssertionInfo, Iterable, int, Condition)to provide a richer fluent api (same logic, only error message differs).
-
assertHaveAtMost
public <E> void assertHaveAtMost(AssertionInfo info, java.lang.Iterable<? extends E> actual, int times, Condition<? super E> condition)
An alias method ofassertAreAtMost(AssertionInfo, Iterable, int, Condition)to provide a richer fluent api (same logic, only error message differs).
-
assertDoNotHaveAtMost
public <E> void assertDoNotHaveAtMost(AssertionInfo info, java.lang.Iterable<? extends E> actual, int times, Condition<? super E> condition)
An alias method ofassertAreNotAtMost(AssertionInfo, Iterable, int, Condition)to provide a richer fluent api (same logic, only error message differs).
-
assertHaveExactly
public <E> void assertHaveExactly(AssertionInfo info, java.lang.Iterable<? extends E> actual, int times, Condition<? super E> condition)
An alias method ofassertAreExactly(AssertionInfo, Iterable, int, Condition)to provide a richer fluent api (same logic, only error message differs).
-
assertDoNotHaveExactly
public <E> void assertDoNotHaveExactly(AssertionInfo info, java.lang.Iterable<? extends E> actual, int times, Condition<? super E> condition)
An alias method ofassertAreNotExactly(AssertionInfo, Iterable, int, Condition)to provide a richer fluent api (same logic, only error message differs).
-
assertContainsAll
public void assertContainsAll(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Iterable<?> other)
Asserts that the givenIterablecontains all the elements of the otherIterable, in any order.- Parameters:
info- contains information about the assertion.actual- the givenIterable.other- the otherIterable.- Throws:
java.lang.NullPointerException- ifIterableisnull.java.lang.AssertionError- if the givenIterableisnull.java.lang.AssertionError- if the givenIterabledoes not contain all the elements of the otherIterable, in any order.
-
assertContainsExactly
public void assertContainsExactly(AssertionInfo info, java.lang.Iterable<?> actual, java.lang.Object[] values)
Asserts that the givenIterablecontains exactly the given values and nothing else, in order.- Parameters:
info- contains information about the assertion.actual- the givenIterable.values- the values that are expected to be in the givenIterablein order.- Throws:
java.lang.NullPointerException- if the array of values isnull.java.lang.IllegalArgumentException- if the array of values is empty.java.lang.AssertionError- if the givenIterableisnull.java.lang.AssertionError- if the givenIterabledoes not contain the given values or if the givenIterablecontains values that are not in the given array, in order.
-
iterableToLookForIsNull
public static java.lang.NullPointerException iterableToLookForIsNull()
-
iterableToLookForIsEmpty
public static java.lang.IllegalArgumentException iterableToLookForIsEmpty()
-
-