Package org.fest.assertions.api
Class AbstractIterableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.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 java.lang.Iterable<T>,T> extends AbstractAssert<S,A> implements ObjectEnumerableAssert<S,T>
Base class for implementations of
whose actual value type isObjectEnumerableAssert
.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 Modifier Constructor Description protected
AbstractIterableAssert(A actual, java.lang.Class<?> selfType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description S
are(Condition<? super T> condition)
Verifies that each element value satisfies the given conditionS
areAtLeast(int times, Condition<? super T> condition)
Verifies that there is at least n elements in the actual group satisfying the given condition.S
areAtMost(int times, Condition<? super T> condition)
Verifies that there is at most n elements in the actual group satisfying the given condition.S
areExactly(int times, Condition<? super T> condition)
Verifies that there is exactly n elements in the actual group satisfying the given condition.S
areNot(Condition<? super T> condition)
Verifies that each element value not satisfies the given conditionS
areNotAtLeast(int times, Condition<? super T> condition)
Verifies that there is at least n elements in the actual group not satisfying the given condition.S
areNotAtMost(int times, Condition<? super T> condition)
Verifies that there is at most n elements in the actual group not satisfying the given condition.S
areNotExactly(int times, Condition<? super T> condition)
Verifies that there is exactly n elements in the actual group not satisfying the given condition.S
contains(T... values)
Verifies that the actual group contains the given values, in any order.S
containsAll(java.lang.Iterable<? extends T> iterable)
Verifies that the actual group contains all the elements of givenIterable
, in any order.S
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.S
containsNull()
Verifies that the actual group contains at least a null element.S
containsOnly(T... values)
Verifies that the actual group contains only the given values and nothing else, in any order.S
containsSequence(T... sequence)
Verifies that the actual group contains the given sequence, without any other values between them.S
doesNotContain(T... values)
Verifies that the actual group does not contain the given values.S
doesNotContainNull()
Verifies that the actual group does not contain null elements.S
doesNotHaveDuplicates()
Verifies that the actual group does not contain duplicates.S
doNotHave(Condition<? super T> condition)
Verifies that each element value not satisfies the given conditionS
doNotHaveAtLeast(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areNotAtLeast(int, Condition)
.S
doNotHaveAtMost(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areNotAtMost(int, Condition)
.S
doNotHaveExactly(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areNotExactly(int, Condition)
.S
endsWith(T... sequence)
Verifies that the actual group ends with the given sequence of objects, without any other objects between them.S
hasSameSizeAs(java.lang.Iterable<?> other)
Verifies that the actual group has the same size as givenIterable
.S
hasSameSizeAs(java.lang.Object[] other)
Verifies that the actual group has the same size as given array.S
hasSize(int expected)
Verifies that the number of values in the actual group is equal to the given one.S
have(Condition<? super T> condition)
Verifies that each element value satisfies the given conditionS
haveAtLeast(int times, Condition<? super T> condition)
This method is an alias forObjectEnumerableAssert.areAtLeast(int, Condition)
.S
haveAtMost(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areAtMost(int, Condition)
.S
haveExactly(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areExactly(int, Condition)
.void
isEmpty()
Verifies that the actual group of values is empty.S
isNotEmpty()
Verifies that the actual group of values is not empty.void
isNullOrEmpty()
Verifies that the actual group of values isnull
or empty.S
isSubsetOf(java.lang.Iterable<? extends T> values)
Verifies that all the elements of the actualIterable
are present in the givenIterable
.S
startsWith(T... sequence)
Verifies that the actual group starts with the given sequence of objects, without any other objects between them.S
usingDefaultElementComparator()
Revert to standard comparison for incoming assertion group element checks.S
usingElementComparator(java.util.Comparator<? super T> customComparator)
Use given custom comparator instead of relying on actual type Aequals
method 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 Detail
-
AbstractIterableAssert
protected AbstractIterableAssert(A actual, java.lang.Class<?> selfType)
-
-
Method Detail
-
isNullOrEmpty
public void isNullOrEmpty()
Verifies that the actual group of values isnull
or empty.- Specified by:
isNullOrEmpty
in interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
-
isEmpty
public void isEmpty()
Verifies that the actual group of values is empty.- Specified by:
isEmpty
in interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
-
isNotEmpty
public S isNotEmpty()
Verifies that the actual group of values is not empty.- Specified by:
isNotEmpty
in interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Returns:
this
assertion object.
-
hasSize
public S hasSize(int expected)
Verifies that the number of values in the actual group is equal to the given one.- Specified by:
hasSize
in interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
expected
- the expected number of values in the actual group.- Returns:
this
assertion object.
-
hasSameSizeAs
public S hasSameSizeAs(java.lang.Object[] other)
Verifies that the actual group has the same size as given array.- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
other
- the array to compare size with actual group.- Returns:
this
assertion object.
-
hasSameSizeAs
public S hasSameSizeAs(java.lang.Iterable<?> other)
Verifies that the actual group has the same size as givenIterable
.- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
other
- theIterable
to compare size with actual group.- Returns:
this
assertion object.
-
contains
public S contains(T... values)
Verifies that the actual group contains the given values, in any order.- Specified by:
contains
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
values
- the given values.- Returns:
this
assertion object.
-
containsOnly
public S containsOnly(T... values)
Verifies that the actual group contains only the given values and nothing else, in any order.- Specified by:
containsOnly
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
values
- the given values.- Returns:
this
assertion object.
-
containsExactly
public S 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. 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:
containsExactly
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
values
- the given values.- Returns:
this
assertion object.
-
isSubsetOf
public S isSubsetOf(java.lang.Iterable<? extends T> values)
Verifies that all the elements of the actualIterable
are present in the givenIterable
.- Parameters:
values
- theIterable
that should contain all actual elements.- Returns:
- this assertion object.
- Throws:
java.lang.AssertionError
- if the actualIterable
isnull
.java.lang.NullPointerException
- if the givenIterable
isnull
.java.lang.AssertionError
- if the actualIterable
is not subset of setIterable
.
-
containsSequence
public S containsSequence(T... sequence)
Verifies that the actual group contains the given sequence, without any other values between them.- Specified by:
containsSequence
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
sequence
- the sequence of objects to look for.- Returns:
- this assertion object.
-
doesNotContain
public S doesNotContain(T... values)
Verifies that the actual group does not contain the given values.- Specified by:
doesNotContain
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
values
- the given values.- Returns:
this
assertion object.
-
doesNotHaveDuplicates
public S doesNotHaveDuplicates()
Verifies that the actual group does not contain duplicates.- Specified by:
doesNotHaveDuplicates
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Returns:
this
assertion object.
-
startsWith
public S startsWith(T... sequence)
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:
startsWith
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
sequence
- the sequence of objects to look for.- Returns:
- this assertion object.
-
endsWith
public S endsWith(T... sequence)
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:
endsWith
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
sequence
- the sequence of objects to look for.- Returns:
- this assertion object.
-
containsNull
public S containsNull()
Verifies that the actual group contains at least a null element.- Specified by:
containsNull
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Returns:
this
assertion object.
-
doesNotContainNull
public S doesNotContainNull()
Verifies that the actual group does not contain null elements.- Specified by:
doesNotContainNull
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Returns:
this
assertion object.
-
are
public S are(Condition<? super T> condition)
Verifies that each element value satisfies the given condition- Specified by:
are
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
condition
- the given condition.- Returns:
this
object.
-
areNot
public S areNot(Condition<? super T> condition)
Verifies that each element value not satisfies the given condition- Specified by:
areNot
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
condition
- the given condition.- Returns:
this
object.
-
have
public S have(Condition<? super T> condition)
Verifies that each element value satisfies the given condition- Specified by:
have
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
condition
- the given condition.- Returns:
this
object.
-
doNotHave
public S doNotHave(Condition<? super T> condition)
Verifies that each element value not satisfies the given condition- Specified by:
doNotHave
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
condition
- the given condition.- Returns:
this
object.
-
areAtLeast
public S areAtLeast(int times, Condition<? super T> condition)
Verifies that there is at least n elements in the actual group satisfying the given condition.- Specified by:
areAtLeast
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
times
- the minimum number of times the condition should be verified.condition
- the given condition.- Returns:
this
object.
-
areNotAtLeast
public S areNotAtLeast(int times, Condition<? super T> condition)
Verifies that there is at least n elements in the actual group not satisfying the given condition.- Specified by:
areNotAtLeast
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
times
- the number of times the condition should not be verified at least.condition
- the given condition.- Returns:
this
object.
-
areAtMost
public S areAtMost(int times, Condition<? super T> condition)
Verifies that there is at most n elements in the actual group satisfying the given condition.- Specified by:
areAtMost
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
times
- the number of times the condition should be at most verified.condition
- the given condition.- Returns:
this
object.
-
areNotAtMost
public S areNotAtMost(int times, Condition<? super T> condition)
Verifies that there is at most n elements in the actual group not satisfying the given condition.- Specified by:
areNotAtMost
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
times
- the number of times the condition should not be verified at most.condition
- the given condition.- Returns:
this
object.
-
areExactly
public S areExactly(int times, Condition<? super T> condition)
Verifies that there is exactly n elements in the actual group satisfying the given condition.- Specified by:
areExactly
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
times
- the exact number of times the condition should be verified.condition
- the given condition.- Returns:
this
object.
-
areNotExactly
public S areNotExactly(int times, Condition<? super T> condition)
Verifies that there is exactly n elements in the actual group not satisfying the given condition.- Specified by:
areNotExactly
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
times
- the exact number of times the condition should not be verified.condition
- the given condition.- Returns:
this
object.
-
haveAtLeast
public S haveAtLeast(int times, Condition<? super T> condition)
This method is an alias forObjectEnumerableAssert.areAtLeast(int, Condition)
.- Specified by:
haveAtLeast
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
-
doNotHaveAtLeast
public S doNotHaveAtLeast(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areNotAtLeast(int, Condition)
.- Specified by:
doNotHaveAtLeast
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
-
haveAtMost
public S haveAtMost(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areAtMost(int, Condition)
.- Specified by:
haveAtMost
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
-
doNotHaveAtMost
public S doNotHaveAtMost(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areNotAtMost(int, Condition)
.- Specified by:
doNotHaveAtMost
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
-
haveExactly
public S haveExactly(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areExactly(int, Condition)
.- Specified by:
haveExactly
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
-
doNotHaveExactly
public S doNotHaveExactly(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areNotExactly(int, Condition)
.- Specified by:
doNotHaveExactly
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
-
containsAll
public S containsAll(java.lang.Iterable<? extends T> iterable)
Verifies that the actual group contains all the elements of givenIterable
, in any order.- Specified by:
containsAll
in interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
iterable
- the givenIterable
we will get elements from.- Returns:
this
assertion object.
-
usingElementComparator
public S usingElementComparator(java.util.Comparator<? super T> customComparator)
Use given custom comparator instead of relying on actual type Aequals
method 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:
usingElementComparator
in interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.
-
usingDefaultElementComparator
public S 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:
usingDefaultElementComparator
in interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>
- Returns:
this
assertion object.
-
-