Class ObjectArrayAssert<ELEMENT>
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<SELF,ELEMENT[]>
-
- org.assertj.core.api.AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>
-
- org.assertj.core.api.ObjectArrayAssert<ELEMENT>
-
- Type Parameters:
ELEMENT- the type of elements of the "actual" value.
- All Implemented Interfaces:
ArraySortedAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>,Assert<ObjectArrayAssert<ELEMENT>,ELEMENT[]>,Descriptable<ObjectArrayAssert<ELEMENT>>,EnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>,ExtensionPoints<ObjectArrayAssert<ELEMENT>,ELEMENT[]>,IndexedObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>,ObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>
public class ObjectArrayAssert<ELEMENT> extends AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>
Assertion methods for arrays of objects.To create an instance of this class, invoke
.Assertions.assertThat(Object[])- Author:
- Yvonne Wang, Alex Ruiz, Joel Costigliola, Nicolas François, Mikhail Mazursky
-
-
Field Summary
-
Fields inherited from class org.assertj.core.api.AbstractObjectArrayAssert
arrays, comparatorsByType, comparatorsForElementPropertyOrFieldNames, comparatorsForElementPropertyOrFieldTypes, iterables
-
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, assertionErrorCreator, conditions, info, myself, objects, throwUnsupportedExceptionOnEquals
-
-
Constructor Summary
Constructors Constructor Description ObjectArrayAssert(ELEMENT[] actual)ObjectArrayAssert(AtomicReferenceArray<ELEMENT> actual)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectArrayAssert<ELEMENT>contains(ELEMENT... values)Verifies that the actual array contains the given values, in any order.ObjectArrayAssert<ELEMENT>containsAnyOf(ELEMENT... values)Verifies that the actual array contains at least one of the given values.ObjectArrayAssert<ELEMENT>containsExactly(ELEMENT... values)Verifies that the actual array contains exactly the given values and nothing else, in order.ObjectArrayAssert<ELEMENT>containsExactlyInAnyOrder(ELEMENT... values)Verifies that the actual array contains exactly the given values and nothing else, in any order.ObjectArrayAssert<ELEMENT>containsOnly(ELEMENT... values)Verifies that the actual array contains only the given values and nothing else, in any order and ignoring duplicates (i.e.ObjectArrayAssert<ELEMENT>containsOnlyOnce(ELEMENT... values)Verifies that the actual array contains the given values only once.ObjectArrayAssert<ELEMENT>containsSequence(ELEMENT... sequence)Verifies that the actual array contains the given sequence in the correct order and without extra values between the sequence values.ObjectArrayAssert<ELEMENT>containsSubsequence(ELEMENT... sequence)Verifies that the actual array contains the given subsequence in the correct order (possibly with other values between them).ObjectArrayAssert<ELEMENT>doesNotContain(ELEMENT... values)Verifies that the actual array does not contain the given values.ObjectArrayAssert<ELEMENT>doesNotContainSequence(ELEMENT... sequence)Verifies that the actual array does not contain the given sequence in the given order and without extra values between the sequence values.ObjectArrayAssert<ELEMENT>doesNotContainSubsequence(ELEMENT... sequence)Verifies that the actual array does not contain the given subsequence in the correct order (possibly with other values between them).ObjectArrayAssert<ELEMENT>endsWith(ELEMENT first, ELEMENT... rest)Verifies that the actual array ends with the given sequence of objects, without any other objects between them.AbstractListAssert<?,List<? extends Tuple>,Tuple,ObjectAssert<Tuple>>extracting(Function<? super ELEMENT,?>... extractors)ObjectArrayAssert<ELEMENT>isSubsetOf(ELEMENT... values)Verifies that all elements of actual are present in the given values.protected ObjectArrayAssert<ELEMENT>newObjectArrayAssert(ELEMENT[] array)-
Methods inherited from class org.assertj.core.api.AbstractObjectArrayAssert
allMatch, allMatch, allSatisfy, anyMatch, anySatisfy, are, areAtLeast, areAtLeastOne, areAtMost, areExactly, areNot, as, as, contains, containsAll, containsAnyElementsOf, containsExactlyElementsOf, containsExactlyInAnyOrderElementsOf, containsNull, containsOnlyElementsOf, containsOnlyNulls, containsSequence, containsSubsequence, doesNotContain, doesNotContainAnyElementsOf, doesNotContainNull, doesNotContainSequence, doesNotContainSubsequence, doesNotHaveAnyElementsOfTypes, doesNotHaveDuplicates, doNotHave, endsWith, extracting, extracting, extracting, extracting, extracting, extractingResultOf, extractingResultOf, filteredOn, filteredOn, filteredOn, filteredOn, filteredOnAssertions, filteredOnNull, flatExtracting, flatExtracting, flatExtracting, getComparatorsByType, getComparatorsForElementPropertyOrFieldTypes, hasAtLeastOneElementOfType, hasOnlyElementsOfType, hasOnlyElementsOfTypes, hasOnlyOneElementSatisfying, hasSameElementsAs, hasSameSizeAs, hasSameSizeAs, hasSize, hasSizeBetween, hasSizeGreaterThan, hasSizeGreaterThanOrEqualTo, hasSizeLessThan, hasSizeLessThanOrEqualTo, have, haveAtLeast, haveAtLeastOne, haveAtMost, haveExactly, inBinary, inHexadecimal, isEmpty, isNotEmpty, isNullOrEmpty, isSorted, isSortedAccordingTo, isSubsetOf, newListAssertInstance, noneMatch, noneSatisfy, startsWith, usingComparatorForElementFieldsWithNames, usingComparatorForElementFieldsWithType, usingComparatorForType, usingDefaultElementComparator, usingElementComparator, usingElementComparatorIgnoringFields, usingElementComparatorOnFields, usingFieldByFieldElementComparator, usingRecursiveFieldByFieldElementComparator, withAssertionState, withComparatorsForElementPropertyOrFieldNames, withComparatorsForElementPropertyOrFieldTypes, withIterables, withObjectArrays, withTypeComparators, zipSatisfy
-
Methods inherited from class org.assertj.core.api.AbstractAssert
asInstanceOf, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, overridingErrorMessage, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, withFailMessage, withRepresentation, withThreadDumpOnError
-
-
-
-
Constructor Detail
-
ObjectArrayAssert
public ObjectArrayAssert(ELEMENT[] actual)
-
ObjectArrayAssert
public ObjectArrayAssert(AtomicReferenceArray<ELEMENT> actual)
-
-
Method Detail
-
newObjectArrayAssert
protected ObjectArrayAssert<ELEMENT> newObjectArrayAssert(ELEMENT[] array)
- Specified by:
newObjectArrayAssertin classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>
-
extracting
@SafeVarargs public final AbstractListAssert<?,List<? extends Tuple>,Tuple,ObjectAssert<Tuple>> extracting(Function<? super ELEMENT,?>... extractors)
Description copied from class:AbstractObjectArrayAssertUse the givenFunctions to extract the values from the array's elements into a new list composed ofTuples (a simple data structure containing the extracted values), this new list becoming the object under test.It allows you to test values from the array's elements instead of testing the elements themselves, which sometimes can be much less work!
The
Tupledata corresponds to the extracted values from the arrays's elements, for instance if you pass functions extracting "id", "name" and "email" values then eachTuple's data will be composed of an id, a name and an email extracted from the element of the initial array (the Tuple's data order is the same as the given functions order).Let's take a look at an example to make things clearer :
You can use lambda expression or a method reference to extract the expected values.// Build an 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 'name', 'age' and Race of some TolkienCharacter in fellowshipOfTheRing : assertThat(fellowshipOfTheRing).extracting(TolkienCharacter::getName, character -> character.getAge(), TolkienCharacter::getRace) .containsOnly(tuple("Frodo", 33, HOBBIT), tuple("Sam", 38, HOBBIT), tuple("Gandalf", 2020, MAIA), tuple("Legolas", 1000, ELF), tuple("Pippin", 28, HOBBIT), tuple("Gimli", 139, DWARF), tuple("Aragorn", 87, MAN), tuple("Boromir", 37, MAN));Use
Tuple.tuple(Object...)to initialize the expected values.Note that the order of the extracted tuples list is consistent with the iteration order of the array under test, for example if it's a
HashSet, you won't be able to make any assumptions on the extracted tuples order.- Overrides:
extractingin classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
extractors- the extractor functions to extract a value from an element of the array under test.- Returns:
- a new assertion object whose object under test is the list of Tuples containing the extracted values.
-
contains
@SafeVarargs public final ObjectArrayAssert<ELEMENT> contains(ELEMENT... values)
Description copied from class:AbstractObjectArrayAssertVerifies that the actual array contains the given values, in any order.Example :
String[] abc = {"a", "b", "c"}; // assertions will pass assertThat(abc).contains("b", "a"); assertThat(abc).contains("b", "a", "b"); // assertions will fail assertThat(abc).contains("d"); assertThat(abc).contains("c", "d");- Specified by:
containsin interfaceObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>- Overrides:
containsin classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
values- the given values.- Returns:
thisassertion object.
-
containsOnly
@SafeVarargs public final ObjectArrayAssert<ELEMENT> containsOnly(ELEMENT... values)
Description copied from class:AbstractObjectArrayAssertVerifies that the actual array contains only the given values and nothing else, in any order and ignoring duplicates (i.e. once a value is found, its duplicates are also considered found).If you need to check exactly the elements and their duplicates use:
containsExactly(Object...)if the order does mattercontainsExactlyInAnyOrder(Object...)if the order does not matter
String[] abc = {"a", "b", "c"}; // assertions succeed assertThat(abc).containsOnly("c", "b", "a"); // duplicates are ignored assertThat(abc).containsOnly("a", "a", "b", "c", "c"); // ... on both actual and expected values assertThat(new String[] { "a", "a", "b" }).containsOnly("a", "b") .containsOnly("a", "a", "b", "b"); // assertion will fail because the given values do not contain "c" assertThat(abc).containsOnly("a", "b"); // assertion will fail because abc does not contain "d" assertThat(abc).containsOnly("a", "b", "c", "d");- Specified by:
containsOnlyin interfaceObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>- Overrides:
containsOnlyin classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
values- the given values.- Returns:
thisassertion object.
-
containsOnlyOnce
@SafeVarargs public final ObjectArrayAssert<ELEMENT> containsOnlyOnce(ELEMENT... values)
Description copied from class:AbstractObjectArrayAssertVerifies that the actual array contains the given values only once.Examples :
// array is a factory method to create arrays. // assertions will pass assertThat(array("winter", "is", "coming")).containsOnlyOnce("winter"); assertThat(array("winter", "is", "coming")).containsOnlyOnce("coming", "winter"); // assertions will fail assertThat(array("winter", "is", "coming")).containsOnlyOnce("Lannister"); assertThat(array("Arya", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark"); assertThat(array("Arya", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark", "Lannister", "Arya");- Specified by:
containsOnlyOncein interfaceObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>- Overrides:
containsOnlyOncein classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
values- the given values.- Returns:
thisassertion object.
-
containsExactly
@SafeVarargs public final ObjectArrayAssert<ELEMENT> containsExactly(ELEMENT... values)
Description copied from class:AbstractObjectArrayAssertVerifies that the actual array contains exactly the given values and nothing else, in order.
Example :
Ring[] elvesRings = {vilya, nenya, narya}; // assertion will pass assertThat(elvesRings).containsExactly(vilya, nenya, narya); // assertion will fail as actual and expected order differ assertThat(elvesRings).containsExactly(nenya, vilya, narya);- Specified by:
containsExactlyin interfaceObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>- Overrides:
containsExactlyin classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
values- the given values.- Returns:
thisassertion object.
-
containsExactlyInAnyOrder
@SafeVarargs public final ObjectArrayAssert<ELEMENT> containsExactlyInAnyOrder(ELEMENT... values)
Description copied from class:AbstractObjectArrayAssertVerifies that the actual array contains exactly the given values and nothing else, in any order.
Example :
Ring[] elvesRings = {vilya, nenya, narya, vilya}; // assertion will pass assertThat(elvesRings).containsExactlyInAnyOrder(vilya, vilya, nenya, narya); // assertion will fail as vilya exists twice in elvesRings assertThat(elvesRings).containsExactlyInAnyOrder(nenya, vilya, narya);- Specified by:
containsExactlyInAnyOrderin interfaceObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>- Overrides:
containsExactlyInAnyOrderin classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
values- the given values.- Returns:
thisassertion object.
-
containsAnyOf
@SafeVarargs public final ObjectArrayAssert<ELEMENT> containsAnyOf(ELEMENT... values)
Description copied from class:AbstractObjectArrayAssertVerifies that the actual array contains at least one of the given values.Example :
String[] abc = {"a", "b", "c"}; // assertions will pass assertThat(abc).containsAnyOf("b") .containsAnyOf("b", "c") .containsAnyOf("a", "b", "c") .containsAnyOf("a", "b", "c", "d") .containsAnyOf("e", "f", "g", "b"); // assertions will fail assertThat(abc).containsAnyOf("d"); assertThat(abc).containsAnyOf("d", "e", "f", "g");- Specified by:
containsAnyOfin interfaceObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>- Overrides:
containsAnyOfin classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
values- the values whose at least one which is expected to be in the array under test.- Returns:
thisassertion object.
-
isSubsetOf
@SafeVarargs public final ObjectArrayAssert<ELEMENT> isSubsetOf(ELEMENT... values)
Description copied from class:AbstractObjectArrayAssertVerifies that all elements of actual are present in the given values.Example:
Ring[] elvesRings = {vilya, nenya, narya}; // assertions will pass: assertThat(elvesRings).isSubsetOf(vilya, nenya, narya); assertThat(elvesRings).isSubsetOf(vilya, nenya, narya, dwarfRing); // assertions will fail: assertThat(elvesRings).isSubsetOf(vilya, nenya); assertThat(elvesRings).isSubsetOf(vilya, nenya, dwarfRing);- Specified by:
isSubsetOfin interfaceObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>- Overrides:
isSubsetOfin classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
values- the values that should be used for checking the elements of actual.- Returns:
- this assertion object.
-
containsSequence
@SafeVarargs public final ObjectArrayAssert<ELEMENT> containsSequence(ELEMENT... sequence)
Description copied from class:AbstractObjectArrayAssertVerifies that the actual array contains the given sequence in the correct order and without extra values between the sequence values.Use
AbstractObjectArrayAssert.containsSubsequence(Object...)to allow values between the expected sequence values.Example:
Ring[] elvesRings = {vilya, nenya, narya}; // assertion will pass assertThat(elvesRings).containsSequence(vilya, nenya); assertThat(elvesRings).containsSequence(nenya, narya); // assertions will fail, the elements order is correct but there is a value between them (nenya) assertThat(elvesRings).containsSequence(vilya, narya); assertThat(elvesRings).containsSequence(nenya, vilya);- Specified by:
containsSequencein interfaceObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>- Overrides:
containsSequencein classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
sequence- the sequence of objects to look for.- Returns:
- this assertion object.
-
doesNotContainSequence
@SafeVarargs public final ObjectArrayAssert<ELEMENT> doesNotContainSequence(ELEMENT... sequence)
Description copied from class:AbstractObjectArrayAssertVerifies that the actual array does not contain the given sequence in the given order and without extra values between the sequence values.Use
AbstractObjectArrayAssert.doesNotContainSubsequence(Object...)to also ensure the sequence does not exist with values between the expected sequence values.Example:
Ring[] elvesRings = {vilya, nenya, narya}; // assertion will pass, the elements order is correct but there is a value between them (nenya) assertThat(elvesRings).containsSequence(vilya, narya); assertThat(elvesRings).containsSequence(nenya, vilya); // assertions will fail assertThat(elvesRings).containsSequence(vilya, nenya); assertThat(elvesRings).containsSequence(nenya, narya);- Specified by:
doesNotContainSequencein interfaceObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>- Overrides:
doesNotContainSequencein classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
sequence- the sequence of objects to look for.- Returns:
- this assertion object.
-
containsSubsequence
@SafeVarargs public final ObjectArrayAssert<ELEMENT> containsSubsequence(ELEMENT... sequence)
Description copied from class:AbstractObjectArrayAssertVerifies that the actual array contains the given subsequence in the correct order (possibly with other values between them).Example:
Ring[] elvesRings = {vilya, nenya, narya}; // assertions will pass assertThat(elvesRings).containsSubsequence(vilya, nenya); assertThat(elvesRings).containsSubsequence(vilya, narya); // assertion will fail assertThat(elvesRings).containsSubsequence(nenya, vilya);- Specified by:
containsSubsequencein interfaceObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>- Overrides:
containsSubsequencein classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
sequence- the subsequence of objects to look for.- Returns:
- this assertion object.
-
doesNotContainSubsequence
@SafeVarargs public final ObjectArrayAssert<ELEMENT> doesNotContainSubsequence(ELEMENT... sequence)
Description copied from class:AbstractObjectArrayAssertVerifies that the actual array does not contain the given subsequence in the correct order (possibly with other values between them).Example:
Ring[] elvesRings = {vilya, nenya, narya}; // assertions will pass assertThat(elvesRings).doesNotContainSubsequence(nenya, vilya); // assertion will fail assertThat(elvesRings).doesNotContainSubsequence(vilya, nenya); assertThat(elvesRings).doesNotContainSubsequence(vilya, narya);- Specified by:
doesNotContainSubsequencein interfaceObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>- Overrides:
doesNotContainSubsequencein classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
sequence- the subsequence of objects to look for.- Returns:
- this assertion object.
-
doesNotContain
@SafeVarargs public final ObjectArrayAssert<ELEMENT> doesNotContain(ELEMENT... values)
Description copied from class:AbstractObjectArrayAssertVerifies that the actual array does not contain the given values.Example :
String[] abc = {"a", "b", "c"}; // assertion will pass assertThat(abc).doesNotContain("d", "e"); // assertions will fail assertThat(abc).doesNotContain("a"); assertThat(abc).doesNotContain("a", "b", "c"); assertThat(abc).doesNotContain("a", "x");- Specified by:
doesNotContainin interfaceObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>- Overrides:
doesNotContainin classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
values- the given values.- Returns:
thisassertion object.
-
endsWith
@SafeVarargs public final ObjectArrayAssert<ELEMENT> endsWith(ELEMENT first, ELEMENT... rest)
Description copied from class:AbstractObjectArrayAssertVerifies that the actual array 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 array.AbstractObjectArrayAssert.containsSequence(Object...)Example :
String[] abc = {"a", "b", "c"}; // assertion will pass assertThat(abc).endsWith("b", "c"); // assertion will fail assertThat(abc).endsWith("a");- Specified by:
endsWithin interfaceObjectEnumerableAssert<AbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>,ELEMENT>- Overrides:
endsWithin classAbstractObjectArrayAssert<ObjectArrayAssert<ELEMENT>,ELEMENT>- Parameters:
first- the first element of the end sequence of objects to look for.rest- the rest of the end sequence of objects to look for.- Returns:
- this assertion object.
-
-