Package org.fest.assertions.api
Class ObjectArrayAssert<T>
- java.lang.Object
-
- org.fest.assertions.api.AbstractAssert<ObjectArrayAssert<T>,T[]>
-
- org.fest.assertions.api.ObjectArrayAssert<T>
-
- Type Parameters:
T
- the type of elements of the "actual" value.
- All Implemented Interfaces:
ArraySortedAssert<ObjectArrayAssert<T>,T>
,Assert<ObjectArrayAssert<T>,T[]>
,Descriptable<ObjectArrayAssert<T>>
,EnumerableAssert<ObjectArrayAssert<T>,T>
,ExtensionPoints<ObjectArrayAssert<T>,T[]>
,IndexedObjectEnumerableAssert<ObjectArrayAssert<T>,T>
,ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
public class ObjectArrayAssert<T> extends AbstractAssert<ObjectArrayAssert<T>,T[]> implements IndexedObjectEnumerableAssert<ObjectArrayAssert<T>,T>, ArraySortedAssert<ObjectArrayAssert<T>,T>
Assertion methods for arrays of objects.To create an instance of this class, invoke
.Assertions#assertThat(T[])
- Author:
- Yvonne Wang, Alex Ruiz, Joel Costigliola, 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
ObjectArrayAssert(T[] actual)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectArrayAssert<T>
are(Condition<? super T> condition)
Verifies that each element value satisfies the given conditionObjectArrayAssert<T>
areAtLeast(int times, Condition<? super T> condition)
Verifies that there is at least n elements in the actual group satisfying the given condition.ObjectArrayAssert<T>
areAtMost(int times, Condition<? super T> condition)
Verifies that there is at most n elements in the actual group satisfying the given condition.ObjectArrayAssert<T>
areExactly(int times, Condition<? super T> condition)
Verifies that there is exactly n elements in the actual group satisfying the given condition.ObjectArrayAssert<T>
areNot(Condition<? super T> condition)
Verifies that each element value not satisfies the given conditionObjectArrayAssert<T>
areNotAtLeast(int times, Condition<? super T> condition)
Verifies that there is at least n elements in the actual group not satisfying the given condition.ObjectArrayAssert<T>
areNotAtMost(int times, Condition<? super T> condition)
Verifies that there is at most n elements in the actual group not satisfying the given condition.ObjectArrayAssert<T>
areNotExactly(int times, Condition<? super T> condition)
Verifies that there is exactly n elements in the actual group not satisfying the given condition.ObjectArrayAssert<T>
contains(T... values)
Verifies that the actual group contains the given values, in any order.ObjectArrayAssert<T>
contains(T value, Index index)
Verifies that the actual group contains the given object at the given index.ObjectArrayAssert<T>
containsAll(java.lang.Iterable<? extends T> iterable)
Verifies that the actual group contains all the elements of givenIterable
, in any order.ObjectArrayAssert<T>
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.ObjectArrayAssert<T>
containsNull()
Verifies that the actual group contains at least a null element.ObjectArrayAssert<T>
containsOnly(T... values)
Verifies that the actual group contains only the given values and nothing else, in any order.ObjectArrayAssert<T>
containsSequence(T... sequence)
Verifies that the actual group contains the given sequence, without any other values between them.ObjectArrayAssert<T>
doesNotContain(T... values)
Verifies that the actual group does not contain the given values.ObjectArrayAssert<T>
doesNotContain(T value, Index index)
Verifies that the actual group does not contain the given object at the given index.ObjectArrayAssert<T>
doesNotContainNull()
Verifies that the actual group does not contain null elements.ObjectArrayAssert<T>
doesNotHaveDuplicates()
Verifies that the actual group does not contain duplicates.ObjectArrayAssert<T>
doNotHave(Condition<? super T> condition)
Verifies that each element value not satisfies the given conditionObjectArrayAssert<T>
doNotHaveAtLeast(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areNotAtLeast(int, Condition)
.ObjectArrayAssert<T>
doNotHaveAtMost(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areNotAtMost(int, Condition)
.ObjectArrayAssert<T>
doNotHaveExactly(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areNotExactly(int, Condition)
.ObjectArrayAssert<T>
endsWith(T... sequence)
Verifies that the actual group ends with the given sequence of objects, without any other objects between them.ObjectArrayAssert<T>
hasSameSizeAs(java.lang.Iterable<?> other)
Verifies that the actual group has the same size as givenIterable
.ObjectArrayAssert<T>
hasSameSizeAs(java.lang.Object[] other)
Verifies that the actual group has the same size as given array.ObjectArrayAssert<T>
hasSize(int expected)
Verifies that the number of values in the actual group is equal to the given one.ObjectArrayAssert<T>
have(Condition<? super T> condition)
Verifies that each element value satisfies the given conditionObjectArrayAssert<T>
haveAtLeast(int times, Condition<? super T> condition)
This method is an alias forObjectEnumerableAssert.areAtLeast(int, Condition)
.ObjectArrayAssert<T>
haveAtMost(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areAtMost(int, Condition)
.ObjectArrayAssert<T>
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.ObjectArrayAssert<T>
isNotEmpty()
Verifies that the actual group of values is not empty.void
isNullOrEmpty()
Verifies that the actual group of values isnull
or empty.ObjectArrayAssert<T>
isSorted()
Verifies that the actual array is sorted into ascending order according to the natural ordering of its elements.ObjectArrayAssert<T>
isSortedAccordingTo(java.util.Comparator<? super T> comparator)
Verifies that the actual array is sorted according to the given comparator. Empty arrays are considered sorted whatever the comparator is. One element arrays are considered sorted if element is compatible with comparator, otherwise an AssertionError is thrown.ObjectArrayAssert<T>
startsWith(T... sequence)
Verifies that the actual group starts with the given sequence of objects, without any other objects between them.ObjectArrayAssert<T>
usingDefaultElementComparator()
Revert to standard comparison for incoming assertion group element checks.ObjectArrayAssert<T>
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
-
ObjectArrayAssert
protected ObjectArrayAssert(T[] actual)
-
-
Method Detail
-
isNullOrEmpty
public void isNullOrEmpty()
Verifies that the actual group of values isnull
or empty.- Specified by:
isNullOrEmpty
in interfaceEnumerableAssert<ObjectArrayAssert<T>,T>
-
isEmpty
public void isEmpty()
Verifies that the actual group of values is empty.- Specified by:
isEmpty
in interfaceEnumerableAssert<ObjectArrayAssert<T>,T>
-
isNotEmpty
public ObjectArrayAssert<T> isNotEmpty()
Verifies that the actual group of values is not empty.- Specified by:
isNotEmpty
in interfaceEnumerableAssert<ObjectArrayAssert<T>,T>
- Returns:
this
assertion object.
-
hasSize
public ObjectArrayAssert<T> hasSize(int expected)
Verifies that the number of values in the actual group is equal to the given one.- Specified by:
hasSize
in interfaceEnumerableAssert<ObjectArrayAssert<T>,T>
- Parameters:
expected
- the expected number of values in the actual group.- Returns:
this
assertion object.
-
hasSameSizeAs
public ObjectArrayAssert<T> hasSameSizeAs(java.lang.Object[] other)
Verifies that the actual group has the same size as given array.- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<ObjectArrayAssert<T>,T>
- Parameters:
other
- the array to compare size with actual group.- Returns:
this
assertion object.
-
hasSameSizeAs
public ObjectArrayAssert<T> hasSameSizeAs(java.lang.Iterable<?> other)
Verifies that the actual group has the same size as givenIterable
.- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<ObjectArrayAssert<T>,T>
- Parameters:
other
- theIterable
to compare size with actual group.- Returns:
this
assertion object.
-
contains
public ObjectArrayAssert<T> contains(T... values)
Verifies that the actual group contains the given values, in any order.- Specified by:
contains
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
- Parameters:
values
- the given values.- Returns:
this
assertion object.
-
containsOnly
public ObjectArrayAssert<T> containsOnly(T... values)
Verifies that the actual group contains only the given values and nothing else, in any order.- Specified by:
containsOnly
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
- Parameters:
values
- the given values.- Returns:
this
assertion object.
-
containsExactly
public ObjectArrayAssert<T> 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<ObjectArrayAssert<T>,T>
- Parameters:
values
- the given values.- Returns:
this
assertion object.
-
containsSequence
public ObjectArrayAssert<T> containsSequence(T... sequence)
Verifies that the actual group contains the given sequence, without any other values between them.- Specified by:
containsSequence
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
- Parameters:
sequence
- the sequence of objects to look for.- Returns:
- this assertion object.
-
contains
public ObjectArrayAssert<T> contains(T value, Index index)
Verifies that the actual group contains the given object at the given index.- Specified by:
contains
in interfaceIndexedObjectEnumerableAssert<ObjectArrayAssert<T>,T>
- Parameters:
value
- the object to look for.index
- the index where the object should be stored in the actual group.- Returns:
- this assertion object.
-
doesNotContain
public ObjectArrayAssert<T> doesNotContain(T value, Index index)
Verifies that the actual group does not contain the given object at the given index.- Specified by:
doesNotContain
in interfaceIndexedObjectEnumerableAssert<ObjectArrayAssert<T>,T>
- Parameters:
value
- the object to look for.index
- the index where the object should be stored in the actual group.- Returns:
- this assertion object.
-
doesNotContain
public ObjectArrayAssert<T> doesNotContain(T... values)
Verifies that the actual group does not contain the given values.- Specified by:
doesNotContain
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
- Parameters:
values
- the given values.- Returns:
this
assertion object.
-
doesNotHaveDuplicates
public ObjectArrayAssert<T> doesNotHaveDuplicates()
Verifies that the actual group does not contain duplicates.- Specified by:
doesNotHaveDuplicates
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
- Returns:
this
assertion object.
-
startsWith
public ObjectArrayAssert<T> 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<ObjectArrayAssert<T>,T>
- Parameters:
sequence
- the sequence of objects to look for.- Returns:
- this assertion object.
-
endsWith
public ObjectArrayAssert<T> 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<ObjectArrayAssert<T>,T>
- Parameters:
sequence
- the sequence of objects to look for.- Returns:
- this assertion object.
-
containsNull
public ObjectArrayAssert<T> containsNull()
Verifies that the actual group contains at least a null element.- Specified by:
containsNull
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
- Returns:
this
assertion object.
-
doesNotContainNull
public ObjectArrayAssert<T> doesNotContainNull()
Verifies that the actual group does not contain null elements.- Specified by:
doesNotContainNull
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
- Returns:
this
assertion object.
-
are
public ObjectArrayAssert<T> are(Condition<? super T> condition)
Verifies that each element value satisfies the given condition- Specified by:
are
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
- Parameters:
condition
- the given condition.- Returns:
this
object.
-
areNot
public ObjectArrayAssert<T> areNot(Condition<? super T> condition)
Verifies that each element value not satisfies the given condition- Specified by:
areNot
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
- Parameters:
condition
- the given condition.- Returns:
this
object.
-
have
public ObjectArrayAssert<T> have(Condition<? super T> condition)
Verifies that each element value satisfies the given condition- Specified by:
have
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
- Parameters:
condition
- the given condition.- Returns:
this
object.
-
doNotHave
public ObjectArrayAssert<T> doNotHave(Condition<? super T> condition)
Verifies that each element value not satisfies the given condition- Specified by:
doNotHave
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
- Parameters:
condition
- the given condition.- Returns:
this
object.
-
areAtLeast
public ObjectArrayAssert<T> 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<ObjectArrayAssert<T>,T>
- Parameters:
times
- the minimum number of times the condition should be verified.condition
- the given condition.- Returns:
this
object.
-
areNotAtLeast
public ObjectArrayAssert<T> 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<ObjectArrayAssert<T>,T>
- Parameters:
times
- the number of times the condition should not be verified at least.condition
- the given condition.- Returns:
this
object.
-
areAtMost
public ObjectArrayAssert<T> 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<ObjectArrayAssert<T>,T>
- Parameters:
times
- the number of times the condition should be at most verified.condition
- the given condition.- Returns:
this
object.
-
areNotAtMost
public ObjectArrayAssert<T> 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<ObjectArrayAssert<T>,T>
- Parameters:
times
- the number of times the condition should not be verified at most.condition
- the given condition.- Returns:
this
object.
-
areExactly
public ObjectArrayAssert<T> 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<ObjectArrayAssert<T>,T>
- Parameters:
times
- the exact number of times the condition should be verified.condition
- the given condition.- Returns:
this
object.
-
areNotExactly
public ObjectArrayAssert<T> 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<ObjectArrayAssert<T>,T>
- Parameters:
times
- the exact number of times the condition should not be verified.condition
- the given condition.- Returns:
this
object.
-
haveAtLeast
public ObjectArrayAssert<T> haveAtLeast(int times, Condition<? super T> condition)
This method is an alias forObjectEnumerableAssert.areAtLeast(int, Condition)
.- Specified by:
haveAtLeast
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
-
doNotHaveAtLeast
public ObjectArrayAssert<T> doNotHaveAtLeast(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areNotAtLeast(int, Condition)
.- Specified by:
doNotHaveAtLeast
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
-
haveAtMost
public ObjectArrayAssert<T> haveAtMost(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areAtMost(int, Condition)
.- Specified by:
haveAtMost
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
-
doNotHaveAtMost
public ObjectArrayAssert<T> doNotHaveAtMost(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areNotAtMost(int, Condition)
.- Specified by:
doNotHaveAtMost
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
-
haveExactly
public ObjectArrayAssert<T> haveExactly(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areExactly(int, Condition)
.- Specified by:
haveExactly
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
-
doNotHaveExactly
public ObjectArrayAssert<T> doNotHaveExactly(int times, Condition<? super T> condition)
This method is an aliasObjectEnumerableAssert.areNotExactly(int, Condition)
.- Specified by:
doNotHaveExactly
in interfaceObjectEnumerableAssert<ObjectArrayAssert<T>,T>
-
isSorted
public ObjectArrayAssert<T> isSorted()
Verifies that the actual array is sorted into ascending order according to the natural ordering of its elements.All array elements must be primitive or implement the
Comparable
interface and must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the array), examples :- a array composed of {2, 4, 6} is ok because the element type is a primitive type.
- a array composed of {"a1", "a2", "a3"} is ok because the element type (String) is Comparable
- a array composed of Rectangle {r1, r2, r3} is NOT ok because Rectangle is not Comparable
- a array composed of {True, "abc", False} is NOT ok because elements are not mutually comparable (even though each element type implements Comparable)
- Specified by:
isSorted
in interfaceArraySortedAssert<ObjectArrayAssert<T>,T>
- Returns:
this
assertion object.
-
isSortedAccordingTo
public ObjectArrayAssert<T> isSortedAccordingTo(java.util.Comparator<? super T> comparator)
Verifies that the actual array is sorted according to the given comparator. Empty arrays are considered sorted whatever the comparator is. One element arrays are considered sorted if element is compatible with comparator, otherwise an AssertionError is thrown.- Specified by:
isSortedAccordingTo
in interfaceArraySortedAssert<ObjectArrayAssert<T>,T>
- Parameters:
comparator
- theComparator
used to compare array elements- Returns:
this
assertion object.
-
containsAll
public ObjectArrayAssert<T> 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<ObjectArrayAssert<T>,T>
- Parameters:
iterable
- the givenIterable
we will get elements from.- Returns:
this
assertion object.
-
usingElementComparator
public ObjectArrayAssert<T> usingElementComparator(java.util.Comparator<? super T> customComparator)
Description copied from interface:EnumerableAssert
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<ObjectArrayAssert<T>,T>
- Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.
-
usingDefaultElementComparator
public ObjectArrayAssert<T> usingDefaultElementComparator()
Description copied from interface:EnumerableAssert
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<ObjectArrayAssert<T>,T>
- Returns:
this
assertion object.
-
-