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 ofwhose 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 protectedAbstractIterableAssert(A actual, java.lang.Class<?> selfType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Sare(Condition<? super T> condition)Verifies that each element value satisfies the given conditionSareAtLeast(int times, Condition<? super T> condition)Verifies that there is at least n elements in the actual group satisfying the given condition.SareAtMost(int times, Condition<? super T> condition)Verifies that there is at most n elements in the actual group satisfying the given condition.SareExactly(int times, Condition<? super T> condition)Verifies that there is exactly n elements in the actual group satisfying the given condition.SareNot(Condition<? super T> condition)Verifies that each element value not satisfies the given conditionSareNotAtLeast(int times, Condition<? super T> condition)Verifies that there is at least n elements in the actual group not satisfying the given condition.SareNotAtMost(int times, Condition<? super T> condition)Verifies that there is at most n elements in the actual group not satisfying the given condition.SareNotExactly(int times, Condition<? super T> condition)Verifies that there is exactly n elements in the actual group not satisfying the given condition.Scontains(T... values)Verifies that the actual group contains the given values, in any order.ScontainsAll(java.lang.Iterable<? extends T> iterable)Verifies that the actual group contains all the elements of givenIterable, in any order.ScontainsExactly(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.ScontainsNull()Verifies that the actual group contains at least a null element.ScontainsOnly(T... values)Verifies that the actual group contains only the given values and nothing else, in any order.ScontainsSequence(T... sequence)Verifies that the actual group contains the given sequence, without any other values between them.SdoesNotContain(T... values)Verifies that the actual group does not contain the given values.SdoesNotContainNull()Verifies that the actual group does not contain null elements.SdoesNotHaveDuplicates()Verifies that the actual group does not contain duplicates.SdoNotHave(Condition<? super T> condition)Verifies that each element value not satisfies the given conditionSdoNotHaveAtLeast(int times, Condition<? super T> condition)This method is an aliasObjectEnumerableAssert.areNotAtLeast(int, Condition).SdoNotHaveAtMost(int times, Condition<? super T> condition)This method is an aliasObjectEnumerableAssert.areNotAtMost(int, Condition).SdoNotHaveExactly(int times, Condition<? super T> condition)This method is an aliasObjectEnumerableAssert.areNotExactly(int, Condition).SendsWith(T... sequence)Verifies that the actual group ends with the given sequence of objects, without any other objects between them.ShasSameSizeAs(java.lang.Iterable<?> other)Verifies that the actual group has the same size as givenIterable.ShasSameSizeAs(java.lang.Object[] other)Verifies that the actual group has the same size as given array.ShasSize(int expected)Verifies that the number of values in the actual group is equal to the given one.Shave(Condition<? super T> condition)Verifies that each element value satisfies the given conditionShaveAtLeast(int times, Condition<? super T> condition)This method is an alias forObjectEnumerableAssert.areAtLeast(int, Condition).ShaveAtMost(int times, Condition<? super T> condition)This method is an aliasObjectEnumerableAssert.areAtMost(int, Condition).ShaveExactly(int times, Condition<? super T> condition)This method is an aliasObjectEnumerableAssert.areExactly(int, Condition).voidisEmpty()Verifies that the actual group of values is empty.SisNotEmpty()Verifies that the actual group of values is not empty.voidisNullOrEmpty()Verifies that the actual group of values isnullor empty.SisSubsetOf(java.lang.Iterable<? extends T> values)Verifies that all the elements of the actualIterableare present in the givenIterable.SstartsWith(T... sequence)Verifies that the actual group starts with the given sequence of objects, without any other objects between them.SusingDefaultElementComparator()Revert to standard comparison for incoming assertion group element checks.SusingElementComparator(java.util.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 Detail
-
AbstractIterableAssert
protected AbstractIterableAssert(A actual, java.lang.Class<?> selfType)
-
-
Method Detail
-
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 java.lang.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 java.lang.Iterable<T>>
-
isNotEmpty
public S isNotEmpty()
Verifies that the actual group of values is not empty.- Specified by:
isNotEmptyin interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Returns:
thisassertion 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:
hasSizein 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:
thisassertion object.
-
hasSameSizeAs
public S hasSameSizeAs(java.lang.Object[] other)
Verifies that the actual group has the same size as given array.- Specified by:
hasSameSizeAsin interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Parameters:
other- the array to compare size with actual group.- Returns:
thisassertion object.
-
hasSameSizeAs
public S hasSameSizeAs(java.lang.Iterable<?> other)
Verifies that the actual group has the same size as givenIterable.- Specified by:
hasSameSizeAsin interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Parameters:
other- theIterableto compare size with actual group.- Returns:
thisassertion object.
-
contains
public S contains(T... values)
Verifies that the actual group contains the given values, in any order.- Specified by:
containsin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Parameters:
values- the given values.- Returns:
thisassertion 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:
containsOnlyin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Parameters:
values- the given values.- Returns:
thisassertion 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:
containsExactlyin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Parameters:
values- the given values.- Returns:
thisassertion object.
-
isSubsetOf
public S isSubsetOf(java.lang.Iterable<? extends T> values)
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:
java.lang.AssertionError- if the actualIterableisnull.java.lang.NullPointerException- if the givenIterableisnull.java.lang.AssertionError- if the actualIterableis 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:
containsSequencein 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:
doesNotContainin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Parameters:
values- the given values.- Returns:
thisassertion object.
-
doesNotHaveDuplicates
public S doesNotHaveDuplicates()
Verifies that the actual group does not contain duplicates.- Specified by:
doesNotHaveDuplicatesin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Returns:
thisassertion 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:
startsWithin 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:
endsWithin 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:
containsNullin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Returns:
thisassertion object.
-
doesNotContainNull
public S doesNotContainNull()
Verifies that the actual group does not contain null elements.- Specified by:
doesNotContainNullin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Returns:
thisassertion object.
-
are
public S are(Condition<? super T> condition)
Verifies that each element value satisfies the given condition- Specified by:
arein interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Parameters:
condition- the given condition.- Returns:
thisobject.
-
areNot
public S areNot(Condition<? super T> condition)
Verifies that each element value not satisfies the given condition- Specified by:
areNotin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Parameters:
condition- the given condition.- Returns:
thisobject.
-
have
public S have(Condition<? super T> condition)
Verifies that each element value satisfies the given condition- Specified by:
havein interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Parameters:
condition- the given condition.- Returns:
thisobject.
-
doNotHave
public S doNotHave(Condition<? super T> condition)
Verifies that each element value not satisfies the given condition- Specified by:
doNotHavein interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Parameters:
condition- the given condition.- Returns:
thisobject.
-
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:
areAtLeastin 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:
thisobject.
-
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:
areNotAtLeastin 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:
thisobject.
-
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:
areAtMostin 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:
thisobject.
-
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:
areNotAtMostin 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:
thisobject.
-
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:
areExactlyin 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:
thisobject.
-
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:
areNotExactlyin 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:
thisobject.
-
haveAtLeast
public S haveAtLeast(int times, Condition<? super T> condition)
This method is an alias forObjectEnumerableAssert.areAtLeast(int, Condition).- Specified by:
haveAtLeastin 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:
doNotHaveAtLeastin 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:
haveAtMostin 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:
doNotHaveAtMostin 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:
haveExactlyin 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:
doNotHaveExactlyin 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:
containsAllin interfaceObjectEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Parameters:
iterable- the givenIterablewe will get elements from.- Returns:
thisassertion object.
-
usingElementComparator
public S usingElementComparator(java.util.Comparator<? super T> customComparator)
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 java.lang.Iterable<T>>- Parameters:
customComparator- the comparator to use for incoming assertion checks.- Returns:
thisassertion 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:
usingDefaultElementComparatorin interfaceEnumerableAssert<S extends AbstractIterableAssert<S,A,T>,A extends java.lang.Iterable<T>>- Returns:
thisassertion object.
-
-