Package org.fest.assertions.api
Class AbstractIterableAssert<S extends AbstractIterableAssert<S,A,T>,A extends Iterable<T>,T>
java.lang.Object
org.fest.assertions.api.AbstractAssert<S,A>
org.fest.assertions.api.AbstractIterableAssert<S,A,T>
- Type Parameters:
S- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.A- the type of the "actual" value.T- the type of elements of the "actual" value.
- All Implemented Interfaces:
Assert<S,,A> Descriptable<S>,EnumerableAssert<S,,T> ExtensionPoints<S,,A> ObjectEnumerableAssert<S,T>
- Direct Known Subclasses:
IterableAssert,ListAssert
public abstract class AbstractIterableAssert<S extends AbstractIterableAssert<S,A,T>,A extends Iterable<T>,T>
extends AbstractAssert<S,A>
implements ObjectEnumerableAssert<S,T>
Base class for implementations of
ObjectEnumerableAssert whose actual value type is
Collection.- Author:
- Yvonne Wang, Alex Ruiz, Mathieu Baechler, Joel Costigliola, Maciej Jaskowski, Nicolas François, Mikhail Mazursky
-
Field Summary
Fields inherited from class org.fest.assertions.api.AbstractAssert
actual, myself -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionVerifies that each element value satisfies the given conditionareAtLeast(int times, Condition<? super T> condition) Verifies that there is at least n elements in the actual group satisfying the given condition.Verifies that there is at most n elements in the actual group satisfying the given condition.areExactly(int times, Condition<? super T> condition) Verifies that there is exactly n elements in the actual group satisfying the given condition.Verifies that each element value not satisfies the given conditionareNotAtLeast(int times, Condition<? super T> condition) Verifies that there is at least n elements in the actual group not satisfying the given condition.areNotAtMost(int times, Condition<? super T> condition) Verifies that there is at most n elements in the actual group not satisfying the given condition.areNotExactly(int times, Condition<? super T> condition) Verifies that there is exactly n elements in the actual group not satisfying the given condition.Verifies that the actual group contains the given values, in any order.containsAll(Iterable<? extends T> iterable) Verifies that the actual group contains all the elements of givenIterable, in any order.containsExactly(T... values) Verifies that the actual group contains only the given values and nothing else, in order.
This assertion should only be used with Iterable that have a consistent iteration order (i.e.Verifies that the actual group contains at least a null element.containsOnly(T... values) Verifies that the actual group contains only the given values and nothing else, in any order.containsSequence(T... sequence) Verifies that the actual group contains the given sequence, without any other values between them.doesNotContain(T... values) Verifies that the actual group does not contain the given values.Verifies that the actual group does not contain null elements.Verifies that the actual group does not contain duplicates.Verifies that each element value not satisfies the given conditiondoNotHaveAtLeast(int times, Condition<? super T> condition) This method is an aliasObjectEnumerableAssert.areNotAtLeast(int, Condition).doNotHaveAtMost(int times, Condition<? super T> condition) This method is an aliasObjectEnumerableAssert.areNotAtMost(int, Condition).doNotHaveExactly(int times, Condition<? super T> condition) This method is an aliasObjectEnumerableAssert.areNotExactly(int, Condition).Verifies that the actual group ends with the given sequence of objects, without any other objects between them.hasSameSizeAs(Iterable<?> other) Verifies that the actual group has the same size as givenIterable.hasSameSizeAs(Object[] other) Verifies that the actual group has the same size as given array.hasSize(int expected) Verifies that the number of values in the actual group is equal to the given one.Verifies that each element value satisfies the given conditionhaveAtLeast(int times, Condition<? super T> condition) This method is an alias forObjectEnumerableAssert.areAtLeast(int, Condition).haveAtMost(int times, Condition<? super T> condition) This method is an aliasObjectEnumerableAssert.areAtMost(int, Condition).haveExactly(int times, Condition<? super T> condition) This method is an aliasObjectEnumerableAssert.areExactly(int, Condition).voidisEmpty()Verifies that the actual group of values is empty.Verifies that the actual group of values is not empty.voidVerifies that the actual group of values isnullor empty.isSubsetOf(Iterable<? extends T> values) Verifies that all the elements of the actualIterableare present in the givenIterable.startsWith(T... sequence) Verifies that the actual group starts with the given sequence of objects, without any other objects between them.Revert to standard comparison for incoming assertion group element checks.usingElementComparator(Comparator<? super T> customComparator) Use given custom comparator instead of relying on actual type Aequalsmethod to compare group elements for incoming assertion checks.Methods inherited from class org.fest.assertions.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, getWritableAssertionInfo, has, hashCode, hasSameClassAs, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, usingComparator, usingDefaultComparator
-
Constructor Details
-
AbstractIterableAssert
-
-
Method Details
-
isNullOrEmpty
public void isNullOrEmpty()Verifies that the actual group of values isnullor empty.- Specified by:
isNullOrEmptyin interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>>
-
isEmpty
public void isEmpty()Verifies that the actual group of values is empty.- Specified by:
isEmptyin interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>>
-
isNotEmpty
Verifies that the actual group of values is not empty.- Specified by:
isNotEmptyin interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Returns:
thisassertion object.
-
hasSize
Verifies that the number of values in the actual group is equal to the given one.- Specified by:
hasSizein interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
expected- the expected number of values in the actual group.- Returns:
thisassertion object.
-
hasSameSizeAs
Verifies that the actual group has the same size as given array.- Specified by:
hasSameSizeAsin interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
other- the array to compare size with actual group.- Returns:
thisassertion object.
-
hasSameSizeAs
Verifies that the actual group has the same size as givenIterable.- Specified by:
hasSameSizeAsin interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
other- theIterableto compare size with actual group.- Returns:
thisassertion object.
-
contains
Verifies that the actual group contains the given values, in any order.- Specified by:
containsin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
values- the given values.- Returns:
thisassertion object.
-
containsOnly
Verifies that the actual group contains only the given values and nothing else, in any order.- Specified by:
containsOnlyin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
values- the given values.- Returns:
thisassertion object.
-
containsExactly
Verifies that the actual group contains only the given values and nothing else, in order.
This assertion should only be used with Iterable that have a consistent iteration order (i.e. don't use it withHashSet, preferObjectEnumerableAssert.containsOnly(Object...)in that case).Example :
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya); // assertion will pass assertThat(elvesRings).containsExactly(vilya, nenya, narya); // assertion will fail as actual and expected orders differ. assertThat(elvesRings).containsExactly(nenya, vilya, narya);
- Specified by:
containsExactlyin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
values- the given values.- Returns:
thisassertion object.
-
isSubsetOf
Verifies that all the elements of the actualIterableare present in the givenIterable.- Parameters:
values- theIterablethat should contain all actual elements.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualIterableisnull.NullPointerException- if the givenIterableisnull.AssertionError- if the actualIterableis not subset of setIterable.
-
containsSequence
Verifies that the actual group contains the given sequence, without any other values between them.- Specified by:
containsSequencein interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
sequence- the sequence of objects to look for.- Returns:
- this assertion object.
-
doesNotContain
Verifies that the actual group does not contain the given values.- Specified by:
doesNotContainin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
values- the given values.- Returns:
thisassertion object.
-
doesNotHaveDuplicates
Verifies that the actual group does not contain duplicates.- Specified by:
doesNotHaveDuplicatesin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Returns:
thisassertion object.
-
startsWith
Verifies that the actual group starts 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 first element of the actual group.ObjectEnumerableAssert.containsSequence(Object...)- Specified by:
startsWithin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
sequence- the sequence of objects to look for.- Returns:
- this assertion object.
-
endsWith
Verifies that the actual group ends 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 last element of the actual group.ObjectEnumerableAssert.containsSequence(Object...)- Specified by:
endsWithin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
sequence- the sequence of objects to look for.- Returns:
- this assertion object.
-
containsNull
Verifies that the actual group contains at least a null element.- Specified by:
containsNullin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Returns:
thisassertion object.
-
doesNotContainNull
Verifies that the actual group does not contain null elements.- Specified by:
doesNotContainNullin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Returns:
thisassertion object.
-
are
Verifies that each element value satisfies the given condition- Specified by:
arein interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
condition- the given condition.- Returns:
thisobject.
-
areNot
Verifies that each element value not satisfies the given condition- Specified by:
areNotin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
condition- the given condition.- Returns:
thisobject.
-
have
Verifies that each element value satisfies the given condition- Specified by:
havein interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
condition- the given condition.- Returns:
thisobject.
-
doNotHave
Verifies that each element value not satisfies the given condition- Specified by:
doNotHavein interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
condition- the given condition.- Returns:
thisobject.
-
areAtLeast
Verifies that there is at least n elements in the actual group satisfying the given condition.- Specified by:
areAtLeastin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
times- the minimum number of times the condition should be verified.condition- the given condition.- Returns:
thisobject.
-
areNotAtLeast
Verifies that there is at least n elements in the actual group not satisfying the given condition.- Specified by:
areNotAtLeastin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
times- the number of times the condition should not be verified at least.condition- the given condition.- Returns:
thisobject.
-
areAtMost
Verifies that there is at most n elements in the actual group satisfying the given condition.- Specified by:
areAtMostin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
times- the number of times the condition should be at most verified.condition- the given condition.- Returns:
thisobject.
-
areNotAtMost
Verifies that there is at most n elements in the actual group not satisfying the given condition.- Specified by:
areNotAtMostin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
times- the number of times the condition should not be verified at most.condition- the given condition.- Returns:
thisobject.
-
areExactly
Verifies that there is exactly n elements in the actual group satisfying the given condition.- Specified by:
areExactlyin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
times- the exact number of times the condition should be verified.condition- the given condition.- Returns:
thisobject.
-
areNotExactly
Verifies that there is exactly n elements in the actual group not satisfying the given condition.- Specified by:
areNotExactlyin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
times- the exact number of times the condition should not be verified.condition- the given condition.- Returns:
thisobject.
-
haveAtLeast
This method is an alias forObjectEnumerableAssert.areAtLeast(int, Condition).- Specified by:
haveAtLeastin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>>
-
doNotHaveAtLeast
This method is an aliasObjectEnumerableAssert.areNotAtLeast(int, Condition).- Specified by:
doNotHaveAtLeastin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>>
-
haveAtMost
This method is an aliasObjectEnumerableAssert.areAtMost(int, Condition).- Specified by:
haveAtMostin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>>
-
doNotHaveAtMost
This method is an aliasObjectEnumerableAssert.areNotAtMost(int, Condition).- Specified by:
doNotHaveAtMostin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>>
-
haveExactly
This method is an aliasObjectEnumerableAssert.areExactly(int, Condition).- Specified by:
haveExactlyin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>>
-
doNotHaveExactly
This method is an aliasObjectEnumerableAssert.areNotExactly(int, Condition).- Specified by:
doNotHaveExactlyin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>>
-
containsAll
Verifies that the actual group contains all the elements of givenIterable, in any order.- Specified by:
containsAllin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
iterable- the givenIterablewe will get elements from.- Returns:
thisassertion object.
-
usingElementComparator
Use given custom comparator instead of relying on actual type Aequalsmethod to compare group elements for incoming assertion checks.Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.
Examples :
// compares invoices by payee assertThat(invoiceList).usingComparator(invoicePayeeComparator).isEqualTo(expectedInvoiceList). // compares invoices by date, doesNotHaveDuplicates and contains both use the given invoice date comparator assertThat(invoiceList).usingComparator(invoiceDateComparator).doesNotHaveDuplicates().contains(may2010Invoice) // as assertThat(invoiceList) creates a new assertion, it falls back to standard comparison strategy // based on Invoice's equal method to compare invoiceList elements to lowestInvoice. assertThat(invoiceList).contains(lowestInvoice). // standard comparison : the fellowshipOfTheRing includes Gandalf but not Sauron (believe me) ... assertThat(fellowshipOfTheRing).contains(gandalf) .doesNotContain(sauron); // ... but if we compare only races, Sauron is in fellowshipOfTheRing because he's a Maia like Gandalf. assertThat(fellowshipOfTheRing).usingElementComparator(raceComparator) .contains(sauron);- Specified by:
usingElementComparatorin interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Parameters:
customComparator- the comparator to use for incoming assertion checks.- Returns:
thisassertion object.
-
usingDefaultElementComparator
Revert to standard comparison for incoming assertion group element checks.This method should be used to disable a custom comparison strategy set by calling
EnumerableAssert.usingElementComparator(Comparator).- Specified by:
usingDefaultElementComparatorin interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A, T>, A extends Iterable<T>> - Returns:
thisassertion object.
-