T
- the type of elements of the "actual" value.public class ObjectArrayAssert<T> extends AbstractAssert<ObjectArrayAssert<T>,T[]> implements IndexedObjectEnumerableAssert<ObjectArrayAssert<T>,T>, ArraySortedAssert<ObjectArrayAssert<T>,T>
To create an instance of this class, invoke
.
Assertions#assertThat(T[])
actual, info, myself
Modifier | Constructor and Description |
---|---|
protected |
ObjectArrayAssert(T[] actual) |
Modifier and Type | Method and Description |
---|---|
ObjectArrayAssert<T> |
are(Condition<? super T> condition)
Verifies that each element value satisfies the given condition
|
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.
|
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 condition
|
ObjectArrayAssert<T> |
areNotAtLeast(int times,
Condition<? super T> condition) |
ObjectArrayAssert<T> |
areNotAtMost(int times,
Condition<? super T> condition) |
ObjectArrayAssert<T> |
areNotExactly(int times,
Condition<? super T> 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(Iterable<? extends T> iterable)
Verifies that the actual group contains all the elements of given
Iterable , 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 condition
|
ObjectArrayAssert<T> |
doNotHaveAtLeast(int times,
Condition<? super T> condition) |
ObjectArrayAssert<T> |
doNotHaveAtMost(int times,
Condition<? super T> condition) |
ObjectArrayAssert<T> |
doNotHaveExactly(int times,
Condition<? super T> 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<Tuple> |
extracting(String... fieldsOrProperties) |
ObjectArrayAssert<Object> |
extracting(String fieldOrProperty)
Extract the values of given field or property from the array's elements under test into a new array, this new array
becoming the array under test.
|
ObjectArrayAssert<T> |
hasSameSizeAs(Iterable<?> other)
Verifies that the actual group has the same size as given
Iterable . |
ObjectArrayAssert<T> |
hasSameSizeAs(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 condition
|
ObjectArrayAssert<T> |
haveAtLeast(int times,
Condition<? super T> condition)
This method is an alias for
ObjectEnumerableAssert.areAtLeast(int, Condition) . |
ObjectArrayAssert<T> |
haveAtMost(int times,
Condition<? super T> condition)
This method is an alias
ObjectEnumerableAssert.areAtMost(int, Condition) . |
ObjectArrayAssert<T> |
haveExactly(int times,
Condition<? super T> condition)
This method is an alias
ObjectEnumerableAssert.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 is
null 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(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(Comparator<? super T> customComparator)
Use given custom comparator instead of relying on actual type A
equals method to compare group elements for
incoming assertion checks. |
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, 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
protected ObjectArrayAssert(T[] actual)
public void isNullOrEmpty()
null
or empty.isNullOrEmpty
in interface EnumerableAssert<ObjectArrayAssert<T>,T>
public void isEmpty()
isEmpty
in interface EnumerableAssert<ObjectArrayAssert<T>,T>
public ObjectArrayAssert<T> isNotEmpty()
isNotEmpty
in interface EnumerableAssert<ObjectArrayAssert<T>,T>
this
assertion object.public ObjectArrayAssert<T> hasSize(int expected)
hasSize
in interface EnumerableAssert<ObjectArrayAssert<T>,T>
expected
- the expected number of values in the actual group.this
assertion object.public ObjectArrayAssert<T> hasSameSizeAs(Object[] other)
hasSameSizeAs
in interface EnumerableAssert<ObjectArrayAssert<T>,T>
other
- the array to compare size with actual group.this
assertion object.public ObjectArrayAssert<T> hasSameSizeAs(Iterable<?> other)
Iterable
.hasSameSizeAs
in interface EnumerableAssert<ObjectArrayAssert<T>,T>
other
- the Iterable
to compare size with actual group.this
assertion object.public ObjectArrayAssert<T> contains(T... values)
contains
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
values
- the given values.this
assertion object.public ObjectArrayAssert<T> containsOnly(T... values)
containsOnly
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
values
- the given values.this
assertion object.public ObjectArrayAssert<T> containsExactly(T... values)
HashSet
, prefer ObjectEnumerableAssert.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);
containsExactly
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
values
- the given values.this
assertion object.public ObjectArrayAssert<T> containsSequence(T... sequence)
containsSequence
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
sequence
- the sequence of objects to look for.public ObjectArrayAssert<T> contains(T value, Index index)
contains
in interface IndexedObjectEnumerableAssert<ObjectArrayAssert<T>,T>
value
- the object to look for.index
- the index where the object should be stored in the actual group.public ObjectArrayAssert<T> doesNotContain(T value, Index index)
doesNotContain
in interface IndexedObjectEnumerableAssert<ObjectArrayAssert<T>,T>
value
- the object to look for.index
- the index where the object should be stored in the actual group.public ObjectArrayAssert<T> doesNotContain(T... values)
doesNotContain
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
values
- the given values.this
assertion object.public ObjectArrayAssert<T> doesNotHaveDuplicates()
doesNotHaveDuplicates
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
this
assertion object.public ObjectArrayAssert<T> startsWith(T... sequence)
ObjectEnumerableAssert.containsSequence(Object...)
, but it also verifies that the first element in the
sequence is also first element of the actual group.startsWith
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
sequence
- the sequence of objects to look for.public ObjectArrayAssert<T> endsWith(T... sequence)
ObjectEnumerableAssert.containsSequence(Object...)
, but it also verifies that the last element in the
sequence is also last element of the actual group.endsWith
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
sequence
- the sequence of objects to look for.public ObjectArrayAssert<T> containsNull()
containsNull
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
this
assertion object.public ObjectArrayAssert<T> doesNotContainNull()
doesNotContainNull
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
this
assertion object.public ObjectArrayAssert<T> are(Condition<? super T> condition)
are
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
condition
- the given condition.this
object.public ObjectArrayAssert<T> areNot(Condition<? super T> condition)
areNot
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
condition
- the given condition.this
object.public ObjectArrayAssert<T> have(Condition<? super T> condition)
have
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
condition
- the given condition.this
object.public ObjectArrayAssert<T> doNotHave(Condition<? super T> condition)
doNotHave
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
condition
- the given condition.this
object.public ObjectArrayAssert<T> areAtLeast(int times, Condition<? super T> condition)
areAtLeast
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
times
- the minimum number of times the condition should be verified.condition
- the given condition.this
object.public ObjectArrayAssert<T> areNotAtLeast(int times, Condition<? super T> condition)
areNotAtLeast
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
times
- the number of times the condition should not be verified at least.condition
- the given condition.this
object.public ObjectArrayAssert<T> areAtMost(int times, Condition<? super T> condition)
areAtMost
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
times
- the number of times the condition should be at most verified.condition
- the given condition.this
object.public ObjectArrayAssert<T> areNotAtMost(int times, Condition<? super T> condition)
areNotAtMost
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
times
- the number of times the condition should not be verified at most.condition
- the given condition.this
object.public ObjectArrayAssert<T> areExactly(int times, Condition<? super T> condition)
areExactly
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
times
- the exact number of times the condition should be verified.condition
- the given condition.this
object.public ObjectArrayAssert<T> areNotExactly(int times, Condition<? super T> condition)
areNotExactly
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
times
- the exact number of times the condition should not be verified.condition
- the given condition.this
object.public ObjectArrayAssert<T> haveAtLeast(int times, Condition<? super T> condition)
ObjectEnumerableAssert.areAtLeast(int, Condition)
.haveAtLeast
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
public ObjectArrayAssert<T> doNotHaveAtLeast(int times, Condition<? super T> condition)
doNotHaveAtLeast
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
public ObjectArrayAssert<T> haveAtMost(int times, Condition<? super T> condition)
ObjectEnumerableAssert.areAtMost(int, Condition)
.haveAtMost
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
public ObjectArrayAssert<T> doNotHaveAtMost(int times, Condition<? super T> condition)
doNotHaveAtMost
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
public ObjectArrayAssert<T> haveExactly(int times, Condition<? super T> condition)
ObjectEnumerableAssert.areExactly(int, Condition)
.haveExactly
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
public ObjectArrayAssert<T> doNotHaveExactly(int times, Condition<? super T> condition)
doNotHaveExactly
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
public ObjectArrayAssert<T> isSorted()
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 :
isSorted
in interface ArraySortedAssert<ObjectArrayAssert<T>,T>
this
assertion object.public ObjectArrayAssert<T> isSortedAccordingTo(Comparator<? super T> comparator)
isSortedAccordingTo
in interface ArraySortedAssert<ObjectArrayAssert<T>,T>
comparator
- the Comparator
used to compare array elementsthis
assertion object.public ObjectArrayAssert<T> containsAll(Iterable<? extends T> iterable)
Iterable
, in any order.containsAll
in interface ObjectEnumerableAssert<ObjectArrayAssert<T>,T>
iterable
- the given Iterable
we will get elements from.this
assertion object.public ObjectArrayAssert<T> usingElementComparator(Comparator<? super T> customComparator)
EnumerableAssert
equals
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);
usingElementComparator
in interface EnumerableAssert<ObjectArrayAssert<T>,T>
customComparator
- the comparator to use for incoming assertion checks.this
assertion object.public ObjectArrayAssert<T> usingDefaultElementComparator()
EnumerableAssert
This method should be used to disable a custom comparison strategy set by calling EnumerableAssert.usingElementComparator(Comparator)
.
usingDefaultElementComparator
in interface EnumerableAssert<ObjectArrayAssert<T>,T>
this
assertion object.public ObjectArrayAssert<Object> extracting(String fieldOrProperty)
It allows you to test a field/property of the array's elements instead of testing the elements themselves, it can be sometimes much less work !
Let's take an example to make things clearer :
// Build a array of TolkienCharacter, a TolkienCharacter has a name (String) and a Race (a class) // they can be public field or properties, both works when extracting their values. TolkienCharacter[] fellowshipOfTheRing = new TolkienCharacter[] { new TolkienCharacter("Frodo", 33, HOBBIT), new TolkienCharacter("Sam", 38, HOBBIT), new TolkienCharacter("Gandalf", 2020, MAIA), new TolkienCharacter("Legolas", 1000, ELF), new TolkienCharacter("Pippin", 28, HOBBIT), new TolkienCharacter("Gimli", 139, DWARF), new TolkienCharacter("Aragorn", 87, MAN, new TolkienCharacter("Boromir", 37, MAN) }; // let's verify the names of TolkienCharacter in fellowshipOfTheRing : assertThat(fellowshipOfTheRing).extracting("name") .contains("Boromir", "Gandalf", "Frodo") .doesNotContain("Sauron", "Elrond"); // you can also extract nested field/property like the name of Race : assertThat(fellowshipOfTheRing).extracting("race.name") .contains("Hobbit", "Elf") .doesNotContain("Orc");A field with the given name is looked for first, if it is not accessible (ie. does not exist or is not public) then a property with the given name is looked for.
It works only if all objects have the field or all objects have the property with the given name, i.e. it won't work if half of the objects have the field and the other the property.
Note that the order of extracted field/property values is consistent with the array order.
fieldOrProperty
- the field/property to extract from the array under testIntrospectionError
- if no field or property exists with the given name (or field exists but is not public)public ObjectArrayAssert<Tuple> extracting(String... fieldsOrProperties)
Copyright © 2013 AssertJ. All Rights Reserved.