Class AtomicReferenceArrayAssert<T>
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<AtomicReferenceArrayAssert<T>,AtomicReferenceArray<T>>
-
- org.assertj.core.api.AtomicReferenceArrayAssert<T>
-
- All Implemented Interfaces:
ArraySortedAssert<AtomicReferenceArrayAssert<T>,T>
,Assert<AtomicReferenceArrayAssert<T>,AtomicReferenceArray<T>>
,Descriptable<AtomicReferenceArrayAssert<T>>
,EnumerableAssert<AtomicReferenceArrayAssert<T>,T>
,ExtensionPoints<AtomicReferenceArrayAssert<T>,AtomicReferenceArray<T>>
,IndexedObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
,ObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
public class AtomicReferenceArrayAssert<T> extends AbstractAssert<AtomicReferenceArrayAssert<T>,AtomicReferenceArray<T>> implements IndexedObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>, ArraySortedAssert<AtomicReferenceArrayAssert<T>,T>
-
-
Field Summary
Fields Modifier and Type Field Description private T[]
array
(package private) org.assertj.core.internal.ObjectArrays
arrays
private org.assertj.core.internal.TypeComparators
comparatorsByType
private Map<String,Comparator<?>>
comparatorsForElementPropertyOrFieldNames
private org.assertj.core.internal.TypeComparators
comparatorsForElementPropertyOrFieldTypes
(package private) org.assertj.core.internal.Iterables
iterables
-
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, assertionErrorCreator, conditions, customRepresentation, info, myself, objects, printAssertionsDescription, throwUnsupportedExceptionOnEquals
-
-
Constructor Summary
Constructors Constructor Description AtomicReferenceArrayAssert(AtomicReferenceArray<T> actual)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description AtomicReferenceArrayAssert<T>
allMatch(Predicate<? super T> predicate)
Verifies that all elements match the givenPredicate
.AtomicReferenceArrayAssert<T>
allMatch(Predicate<? super T> predicate, String predicateDescription)
Verifies that all the elements of actual's array match the givenPredicate
.AtomicReferenceArrayAssert<T>
allSatisfy(Consumer<? super T> requirements)
Verifies that all the elements satisfy given requirements expressed as aConsumer
.AtomicReferenceArrayAssert<T>
allSatisfy(ThrowingConsumer<? super T> requirements)
Verifies that all the elements satisfy the given requirements expressed as aThrowingConsumer
.AtomicReferenceArrayAssert<T>
anyMatch(Predicate<? super T> predicate)
Verifies whether any elements match the providedPredicate
.AtomicReferenceArrayAssert<T>
anySatisfy(Consumer<? super T> requirements)
Verifies that at least one element satisfies the given requirements expressed as aConsumer
.AtomicReferenceArrayAssert<T>
anySatisfy(ThrowingConsumer<? super T> requirements)
Verifies that at least one element satisfies the given requirements expressed as aThrowingConsumer
.AtomicReferenceArrayAssert<T>
are(Condition<? super T> condition)
Verifies that each element value satisfies the given conditionAtomicReferenceArrayAssert<T>
areAtLeast(int times, Condition<? super T> condition)
Verifies that there are at least n elements in the actual AtomicReferenceArray satisfying the given condition.AtomicReferenceArrayAssert<T>
areAtLeastOne(Condition<? super T> condition)
Verifies that there is at least one element in the actual AtomicReferenceArray satisfying the given condition.AtomicReferenceArrayAssert<T>
areAtMost(int times, Condition<? super T> condition)
Verifies that there are at most n elements in the actual AtomicReferenceArray satisfying the given condition.AtomicReferenceArrayAssert<T>
areExactly(int times, Condition<? super T> condition)
Verifies that there are exactly n elements in the actual AtomicReferenceArray satisfying the given condition.AtomicReferenceArrayAssert<T>
areNot(Condition<? super T> condition)
Verifies that each element value does not satisfy the given conditionAtomicReferenceArrayAssert<T>
as(String description, Object... args)
Sets the description of the assertion that is going to be called after.AtomicReferenceArrayAssert<T>
as(Description description)
Sets the description of the assertion that is going to be called after.AtomicReferenceArrayAssert<T>
contains(T... values)
Verifies that the actual AtomicReferenceArray contains the given values, in any order.AtomicReferenceArrayAssert<T>
contains(T value, Index index)
Verifies that the actual AtomicReferenceArray contains the given object at the given index.AtomicReferenceArrayAssert<T>
containsAll(Iterable<? extends T> iterable)
Verifies that the actual AtomicReferenceArray contains all the elements of givenIterable
, in any order.AtomicReferenceArrayAssert<T>
containsAnyElementsOf(Iterable<? extends T> iterable)
Verifies that the actual AtomicReferenceArray contains at least one of the givenIterable
elements.AtomicReferenceArrayAssert<T>
containsAnyOf(T... values)
Verifies that the actual AtomicReferenceArray contains at least one of the given values.protected AtomicReferenceArrayAssert<T>
containsAnyOfForProxy(T[] values)
AtomicReferenceArrayAssert<T>
containsExactly(T... values)
Verifies that the actual AtomicReferenceArray contains only the given values and nothing else, in order.AtomicReferenceArrayAssert<T>
containsExactlyElementsOf(Iterable<? extends T> iterable)
Same ascontainsExactly(Object...)
but handles theIterable
to array conversion : verifies that actual contains all elements of the givenIterable
and nothing else in the same order.protected AtomicReferenceArrayAssert<T>
containsExactlyForProxy(T[] values)
AtomicReferenceArrayAssert<T>
containsExactlyInAnyOrder(T... values)
Verifies that the actual AtomicReferenceArray contains exactly the given values and nothing else, in any order.AtomicReferenceArrayAssert<T>
containsExactlyInAnyOrderElementsOf(Iterable<? extends T> values)
Verifies that the actual AtomicReferenceArray contains exactly the given values and nothing else, in any order.protected AtomicReferenceArrayAssert<T>
containsExactlyInAnyOrderForProxy(T[] values)
protected AtomicReferenceArrayAssert<T>
containsForProxy(T[] values)
AtomicReferenceArrayAssert<T>
containsNull()
Verifies that the actual AtomicReferenceArray contains at least a null element.AtomicReferenceArrayAssert<T>
containsOnly(T... values)
Verifies that the actual AtomicReferenceArray contains only the given values and nothing else, in any order and ignoring duplicates (i.e.AtomicReferenceArrayAssert<T>
containsOnlyElementsOf(Iterable<? extends T> iterable)
Same semantic ascontainsOnly(Object[])
: verifies that actual contains all elements of the givenIterable
and nothing else, in any order and ignoring duplicates (i.e.protected AtomicReferenceArrayAssert<T>
containsOnlyForProxy(T[] values)
AtomicReferenceArrayAssert<T>
containsOnlyNulls()
Verifies that the actual AtomicReferenceArray contains only null elements and nothing else.AtomicReferenceArrayAssert<T>
containsOnlyOnce(T... values)
Verifies that the actual AtomicReferenceArray contains the given values only once.AtomicReferenceArrayAssert<T>
containsOnlyOnceElementsOf(Iterable<? extends T> iterable)
Same semantic asObjectEnumerableAssert.containsOnlyOnce(Object...)
: verifies that the actual group contains the elements of the given iterable only once.protected AtomicReferenceArrayAssert<T>
containsOnlyOnceForProxy(T[] values)
AtomicReferenceArrayAssert<T>
containsSequence(Iterable<? extends T> sequence)
Verifies that the actual AtomicReferenceArray contains the given sequence in the correct order and without extra values between the sequence values.AtomicReferenceArrayAssert<T>
containsSequence(T... sequence)
Verifies that the actual AtomicReferenceArray contains the given sequence in the correct order and without extra values between the sequence values.protected AtomicReferenceArrayAssert<T>
containsSequenceForProxy(T[] sequence)
AtomicReferenceArrayAssert<T>
containsSubsequence(Iterable<? extends T> subsequence)
Verifies that the actual AtomicReferenceArray contains the given subsequence in the correct order (possibly with other values between them).AtomicReferenceArrayAssert<T>
containsSubsequence(T... subsequence)
Verifies that the actual AtomicReferenceArray contains the given subsequence in the correct order (possibly with other values between them).protected AtomicReferenceArrayAssert<T>
containsSubsequenceForProxy(T[] subsequence)
AtomicReferenceArrayAssert<T>
doesNotContain(T... values)
Verifies that the actual AtomicReferenceArray does not contain the given values.AtomicReferenceArrayAssert<T>
doesNotContain(T value, Index index)
Verifies that the actual AtomicReferenceArray does not contain the given object at the given index.AtomicReferenceArrayAssert<T>
doesNotContainAnyElementsOf(Iterable<? extends T> iterable)
Verifies that the actual AtomicReferenceArray does not contain any elements of the givenIterable
(i.e.protected AtomicReferenceArrayAssert<T>
doesNotContainForProxy(T[] values)
AtomicReferenceArrayAssert<T>
doesNotContainNull()
Verifies that the actual AtomicReferenceArray does not contain null elements.AtomicReferenceArrayAssert<T>
doesNotContainSequence(Iterable<? extends T> sequence)
Verifies that the actual AtomicReferenceArray contains the given sequence in the given order and without extra values between the sequence values.AtomicReferenceArrayAssert<T>
doesNotContainSequence(T... sequence)
Verifies that the actual AtomicReferenceArray contains the given sequence in the given order and without extra values between the sequence values.protected AtomicReferenceArrayAssert<T>
doesNotContainSequenceForProxy(T[] sequence)
AtomicReferenceArrayAssert<T>
doesNotContainSubsequence(Iterable<? extends T> subsequence)
Verifies that the actual AtomicReferenceArray does not contain the given subsequence in the correct order (possibly with other values between them).AtomicReferenceArrayAssert<T>
doesNotContainSubsequence(T... subsequence)
Verifies that the actual AtomicReferenceArray does not contain the given subsequence in the correct order (possibly with other values between them).protected AtomicReferenceArrayAssert<T>
doesNotContainSubsequenceForProxy(T[] subsequence)
AtomicReferenceArrayAssert<T>
doesNotHaveAnyElementsOfTypes(Class<?>... unexpectedTypes)
Verifies that all the elements in the actual AtomicReferenceArray do not belong to the specified types (including subclasses).AtomicReferenceArrayAssert<T>
doesNotHaveDuplicates()
Verifies that the actual AtomicReferenceArray does not contain duplicates.private <U,C extends Collection<U>>
ObjectArrayAssert<U>doFlatExtracting(Function<? super T,C> extractor)
AtomicReferenceArrayAssert<T>
doNotHave(Condition<? super T> condition)
Verifies that all elements don't satisfy the given condition.AtomicReferenceArrayAssert<T>
endsWith(T[] sequence)
Verifies that the actual AtomicReferenceArray ends with the given sequence of objects, without any other objects between them.AtomicReferenceArrayAssert<T>
endsWith(T first, T... sequence)
Verifies that the actual AtomicReferenceArray ends with the given sequence of objects, without any other objects between them.protected AtomicReferenceArrayAssert<T>
endsWithForProxy(T first, T[] sequence)
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<Tuple>
extracting(String... propertiesOrFields)
Extract the values of given fields/properties from the array's elements under test into a new array composed of Tuple (a simple data structure), this new array becoming the array under test.<P> ObjectArrayAssert<P>
extracting(String fieldOrProperty, Class<P> extractingType)
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 with type.<U> ObjectArrayAssert<U>
extracting(Function<? super T,U> extractor)
Extract the values from the array's elements by applying an extracting function on them.<U,EXCEPTION extends Exception>
ObjectArrayAssert<U>extracting(ThrowingExtractor<? super T,U,EXCEPTION> extractor)
Extract the values from the array's elements by applying an extracting function (which might throw an exception) on them.ObjectArrayAssert<Object>
extractingResultOf(String method)
Extract the result of given method invocation from the array's elements under test into a new array, this new array becoming the array under test.<P> ObjectArrayAssert<P>
extractingResultOf(String method, Class<P> extractingType)
Extract the result of given method invocation from the array's elements under test into a new array, this new array becoming the array under test.AtomicReferenceArrayAssert<T>
filteredOn(String propertyOrFieldName, Object expectedValue)
Filter the array under test keeping only elements having a property or field equal toexpectedValue
, the property/field is specified bypropertyOrFieldName
parameter.AtomicReferenceArrayAssert<T>
filteredOn(String propertyOrFieldName, FilterOperator<?> filterOperator)
Filter the array under test keeping only elements having a property or field matching the filter expressed with theFilterOperator
, the property/field is specified bypropertyOrFieldName
parameter.<U> AtomicReferenceArrayAssert<T>
filteredOn(Function<? super T,U> function, U expectedValue)
Filter the array under test into a list composed of the elements for which the result of thefunction
is equal toexpectedValue
.AtomicReferenceArrayAssert<T>
filteredOn(Predicate<? super T> predicate)
Filter the array under test into a list composed of the elements matching the givenPredicate
, allowing to perform assertions on the filtered list.AtomicReferenceArrayAssert<T>
filteredOn(Condition<? super T> condition)
Filter the array under test keeping only elements matching the givenCondition
.AtomicReferenceArrayAssert<T>
filteredOnNull(String propertyOrFieldName)
Filter the array under test keeping only elements whose property or field specified bypropertyOrFieldName
is null.ObjectArrayAssert<Object>
flatExtracting(String propertyName)
Extract from array's elements the Iterable/Array values corresponding to the given property/field name and concatenate them into a single array becoming the new object under test.<U,C extends Collection<U>>
ObjectArrayAssert<U>flatExtracting(Function<? super T,C> extractor)
Extract the Iterable values from the array's elements by applying an Iterable extracting function on them and concatenating the result lists into an array which becomes the new object under test.<U,C extends Collection<U>,EXCEPTION extends Exception>
ObjectArrayAssert<U>flatExtracting(ThrowingExtractor<? super T,C,EXCEPTION> extractor)
Extract the Iterable values from the array's elements by applying an Iterable extracting function (which might throw an exception) on them and concatenating the result lists into an array which becomes the new object under test.protected org.assertj.core.internal.TypeComparators
getComparatorsByType()
protected org.assertj.core.internal.TypeComparators
getComparatorsForElementPropertyOrFieldTypes()
AtomicReferenceArrayAssert<T>
hasArray(T[] expected)
Verifies that the AtomicReferenceArray has the given array.AtomicReferenceArrayAssert<T>
hasAtLeastOneElementOfType(Class<?> expectedType)
Verifies that at least one element in the actual AtomicReferenceArray has the specified type (matching includes subclasses of the given type).AtomicReferenceArrayAssert<T>
hasExactlyElementsOfTypes(Class<?>... expectedTypes)
Verifies that the actual elements are of the given types in the given order, there should be as many expected types as there are actual elements.AtomicReferenceArrayAssert<T>
hasOnlyElementsOfType(Class<?> expectedType)
Verifies that all the elements in the actual AtomicReferenceArray belong to the specified type (matching includes subclasses of the given type).AtomicReferenceArrayAssert<T>
hasOnlyElementsOfTypes(Class<?>... types)
Verifies that all elements of the actual group are instances of given classes or interfaces.AtomicReferenceArrayAssert<T>
hasOnlyOneElementSatisfying(Consumer<? super T> elementAssertions)
Verifies that the unique element of theAtomicReferenceArray
satisfies the given assertions expressed as aConsumer
, if it does not, only the first error is reported, useSoftAssertions
to get all the errors.AtomicReferenceArrayAssert<T>
hasSameElementsAs(Iterable<? extends T> iterable)
An alias ofcontainsOnlyElementsOf(Iterable)
: verifies that actual contains all elements of the givenIterable
and nothing else, in any order.AtomicReferenceArrayAssert<T>
hasSameSizeAs(Iterable<?> other)
Verifies that the actual AtomicReferenceArray has the same size as the givenIterable
.AtomicReferenceArrayAssert<T>
hasSameSizeAs(Object other)
Verifies that the actual AtomicReferenceArray has the same size as the given array.AtomicReferenceArrayAssert<T>
hasSize(int expected)
Verifies that the number of values in the AtomicReferenceArray is equal to the given one.AtomicReferenceArrayAssert<T>
hasSizeBetween(int lowerBoundary, int higherBoundary)
Verifies that the number of values in the actual array is between the given boundaries (inclusive).AtomicReferenceArrayAssert<T>
hasSizeGreaterThan(int boundary)
Verifies that the number of values in the actual array is greater than the given boundary.AtomicReferenceArrayAssert<T>
hasSizeGreaterThanOrEqualTo(int boundary)
Verifies that the number of values in the actual array is greater than or equal to the given boundary.AtomicReferenceArrayAssert<T>
hasSizeLessThan(int boundary)
Verifies that the number of values in the actual array is less than the given boundary.AtomicReferenceArrayAssert<T>
hasSizeLessThanOrEqualTo(int boundary)
Verifies that the number of values in the actual array is less than or equal to the given boundary.AtomicReferenceArrayAssert<T>
have(Condition<? super T> condition)
Verifies that all elements satisfy the given condition.AtomicReferenceArrayAssert<T>
haveAtLeast(int times, Condition<? super T> condition)
Verifies that there are at least n elements in the actual AtomicReferenceArray satisfying the given condition.AtomicReferenceArrayAssert<T>
haveAtLeastOne(Condition<? super T> condition)
Verifies that there is at least one element in the actual AtomicReferenceArray satisfying the given condition.AtomicReferenceArrayAssert<T>
haveAtMost(int times, Condition<? super T> condition)
Verifies that there are at most n elements in the actual AtomicReferenceArray satisfying the given condition.AtomicReferenceArrayAssert<T>
haveExactly(int times, Condition<? super T> condition)
Verifies that there are exactly n elements in the actual AtomicReferenceArray satisfying the given condition.AtomicReferenceArrayAssert<T>
inBinary()
Use binary object representation instead of standard representation in error messages.AtomicReferenceArrayAssert<T>
inHexadecimal()
Enable hexadecimal object representation of Iterable elements instead of standard java representation in error messages.private AtomicReferenceArrayAssert<T>
internalAllSatisfy(Consumer<? super T> requirements)
private AtomicReferenceArrayAssert<T>
internalAnySatisfy(Consumer<? super T> requirements)
private AtomicReferenceArrayAssert<T>
internalFilteredOn(String propertyOrFieldName, Object expectedValue)
private AtomicReferenceArrayAssert<T>
internalFilteredOn(Predicate<? super T> predicate)
private AtomicReferenceArrayAssert<T>
internalNoneSatisfy(Consumer<? super T> restrictions)
void
isEmpty()
Verifies that the AtomicReferenceArray is empty.AtomicReferenceArrayAssert<T>
isNotEmpty()
Verifies that the AtomicReferenceArray is not empty.void
isNullOrEmpty()
Verifies that the AtomicReferenceArray isnull
or empty.AtomicReferenceArrayAssert<T>
isSorted()
Verifies that the actual array is sorted in ascending order according to the natural ordering of its elements.AtomicReferenceArrayAssert<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 the element is compatible with comparator, otherwise an AssertionError is thrown.AtomicReferenceArrayAssert<T>
isSubsetOf(Iterable<? extends T> values)
Verifies that all elements of actual are present in the givenIterable
.AtomicReferenceArrayAssert<T>
isSubsetOf(T... values)
Verifies that all elements of actual are present in the given values.protected AtomicReferenceArrayAssert<T>
isSubsetOfForProxy(T[] values)
AtomicReferenceArrayAssert<T>
noneMatch(Predicate<? super T> predicate)
Verifies that no elements match the givenPredicate
.AtomicReferenceArrayAssert<T>
noneSatisfy(Consumer<? super T> restrictions)
Verifies that no elements satisfy the given restrictions expressed as aConsumer
.AtomicReferenceArrayAssert<T>
noneSatisfy(ThrowingConsumer<? super T> restrictions)
Verifies that no elements satisfy the given restrictions expressed as aConsumer
.AtomicReferenceArrayAssert<T>
satisfiesExactly(Consumer<? super T>... requirements)
Verifies that each element satisfies the requirements corresponding to its index, so the first element must satisfy the first requirements, the second element the second requirements etc...AtomicReferenceArrayAssert<T>
satisfiesExactly(ThrowingConsumer<? super T>... requirements)
Verifies that each element satisfies the requirements corresponding to its index, so the first element must satisfy the first requirements, the second element the second requirements etc...protected AtomicReferenceArrayAssert<T>
satisfiesExactlyForProxy(Consumer<? super T>[] requirements)
AtomicReferenceArrayAssert<T>
satisfiesExactlyInAnyOrder(Consumer<? super T>... requirements)
Verifies that at least one combination of iterable elements exists that satisfies the consumers in order (there must be as many consumers as iterable elements and once a consumer is matched it cannot be reused to match other elements).AtomicReferenceArrayAssert<T>
satisfiesExactlyInAnyOrder(ThrowingConsumer<? super T>... requirements)
Verifies that at least one combination of iterable elements exists that satisfies theThrowingConsumer
s in order (there must be as many consumers as iterable elements and once a consumer is matched it cannot be reused to match other elements).protected AtomicReferenceArrayAssert<T>
satisfiesExactlyInAnyOrderForProxy(Consumer<? super T>[] requirements)
AtomicReferenceArrayAssert<T>
startsWith(T... sequence)
Verifies that the actual AtomicReferenceArray starts with the given sequence of objects, without any other objects between them.protected AtomicReferenceArrayAssert<T>
startsWithForProxy(T[] sequence)
<C> AtomicReferenceArrayAssert<T>
usingComparatorForElementFieldsWithNames(Comparator<C> comparator, String... elementPropertyOrFieldNames)
Deprecated.This method is used withusingFieldByFieldElementComparator()
which is deprecated in favor ofusingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration)
orAbstractAssert.usingRecursiveComparison()
.<C> AtomicReferenceArrayAssert<T>
usingComparatorForElementFieldsWithType(Comparator<C> comparator, Class<C> type)
Deprecated.This method is used withusingFieldByFieldElementComparator()
which is deprecated in favor ofusingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration)
orAbstractAssert.usingRecursiveComparison()
.<C> AtomicReferenceArrayAssert<T>
usingComparatorForType(Comparator<C> comparator, Class<C> type)
Allows to set a specific comparator for the given type of elements or their fields.AtomicReferenceArrayAssert<T>
usingDefaultElementComparator()
Revert to standard comparison for incoming assertion group element checks.AtomicReferenceArrayAssert<T>
usingElementComparator(Comparator<? super T> elementComparator)
Use given custom comparator instead of relying on actual element typeequals
method to compare AtomicReferenceArray elements for incoming assertion checks.AtomicReferenceArrayAssert<T>
usingElementComparatorIgnoringFields(String... fields)
Deprecated.This method is deprecated because it performs a shallow field by field comparison, i.e.AtomicReferenceArrayAssert<T>
usingElementComparatorOnFields(String... fields)
Deprecated.This method is deprecated because it performs a shallow field by field comparison, i.e.private AtomicReferenceArrayAssert<T>
usingExtendedByTypesElementComparator(Comparator<Object> elementComparator)
AtomicReferenceArrayAssert<T>
usingFieldByFieldElementComparator()
Deprecated.This method is deprecated because it performs a shallow field by field comparison, i.e.AtomicReferenceArrayAssert<T>
usingRecursiveFieldByFieldElementComparator()
Enable using a recursive field by field comparison strategy similar toAbstractAssert.usingRecursiveComparison()
but contrary to the latter you can chain any iterable assertions after this method (this is why this method exists).AtomicReferenceArrayAssert<T>
usingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration configuration)
Enable using a recursive field by field comparison strategy similar toAbstractAssert.usingRecursiveComparison()
but contrary to the latter you can chain any iterable assertions after this method (this is why this method exists).AtomicReferenceArrayAssert<T>
usingRecursiveFieldByFieldElementComparatorIgnoringFields(String... fields)
The assertions chained after this method will use a recursive field by field comparison on all fields (including inherited fields) except the given ones instead of relying on the elementequals
method.AtomicReferenceArrayAssert<T>
usingRecursiveFieldByFieldElementComparatorOnFields(String... fields)
The assertions chained after this method will use a recursive field by field comparison on the given fields (including inherited fields) instead of relying on the elementequals
method.-
Methods inherited from class org.assertj.core.api.AbstractAssert
asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingRecursiveComparison, usingRecursiveComparison, withAssertionState, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.assertj.core.api.Descriptable
as, describedAs
-
-
-
-
Field Detail
-
array
private T[] array
-
arrays
org.assertj.core.internal.ObjectArrays arrays
-
iterables
org.assertj.core.internal.Iterables iterables
-
comparatorsByType
private org.assertj.core.internal.TypeComparators comparatorsByType
-
comparatorsForElementPropertyOrFieldNames
private Map<String,Comparator<?>> comparatorsForElementPropertyOrFieldNames
-
comparatorsForElementPropertyOrFieldTypes
private org.assertj.core.internal.TypeComparators comparatorsForElementPropertyOrFieldTypes
-
-
Constructor Detail
-
AtomicReferenceArrayAssert
public AtomicReferenceArrayAssert(AtomicReferenceArray<T> actual)
-
-
Method Detail
-
as
public AtomicReferenceArrayAssert<T> as(Description description)
Description copied from interface:Descriptable
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
This overloaded version of "describedAs" offers more flexibility than the one taking a
String
by allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.- Specified by:
as
in interfaceDescriptable<T>
- Parameters:
description
- the new description to set.- Returns:
this
object.- See Also:
Descriptable.describedAs(Description)
-
as
public AtomicReferenceArrayAssert<T> as(String description, Object... args)
Description copied from interface:Descriptable
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
The description follows
String.format(String, Object...)
syntax.Example :
try { // set an incorrect age to Mr Frodo which is really 33 years old. frodo.setAge(50); // specify a test description (call as() before the assertion !), it supports String format syntax. assertThat(frodo.getAge()).as("check %s's age", frodo.getName()).isEqualTo(33); } catch (AssertionError e) { assertThat(e).hasMessage("[check Frodo's age]\n expected: 33\n but was: 50"); }
- Specified by:
as
in interfaceDescriptable<T>
- Parameters:
description
- the new description to set.args
- optional parameter if description is a format String.- Returns:
this
object.- See Also:
Descriptable.describedAs(String, Object...)
-
isNullOrEmpty
public void isNullOrEmpty()
Verifies that the AtomicReferenceArray isnull
or empty.Example:
// assertions will pass assertThat(new AtomicReferenceArray<>(new String[0])).isNullOrEmpty(); AtomicReferenceArray array = null; assertThat(array).isNullOrEmpty(); // assertion will fail assertThat(new AtomicReferenceArray<>(new String[] {"a", "b", "c"})).isNullOrEmpty();
- Specified by:
isNullOrEmpty
in interfaceEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Throws:
AssertionError
- if the AtomicReferenceArray is notnull
or not empty.- Since:
- 2.7.0 / 3.7.0
-
isEmpty
public void isEmpty()
Verifies that the AtomicReferenceArray is empty.Example:
// assertion will pass assertThat(new AtomicReferenceArray<>(new String[0])).isEmpty(); // assertion will fail assertThat(new AtomicReferenceArray<>(new String[]{"a", "b", "c"})).isEmpty();
- Specified by:
isEmpty
in interfaceEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Throws:
AssertionError
- if the AtomicReferenceArray is not empty.- Since:
- 2.7.0 / 3.7.0
-
isNotEmpty
public AtomicReferenceArrayAssert<T> isNotEmpty()
Verifies that the AtomicReferenceArray is not empty.Example:
// assertion will pass assertThat(new AtomicReferenceArray<>(new String[]{"a", "b", "c"})).isNotEmpty(); // assertion will fail assertThat(new AtomicReferenceArray<>(new String[0])).isNotEmpty();
- Specified by:
isNotEmpty
in interfaceEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Returns:
this
assertion object.- Throws:
AssertionError
- if the AtomicReferenceArray is empty.- Since:
- 2.7.0 / 3.7.0
-
hasArray
public AtomicReferenceArrayAssert<T> hasArray(T[] expected)
Verifies that the AtomicReferenceArray has the given array.Example:
AtomicReferenceArray<String> atomicArray = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); // assertion will pass assertThat(atomicArray).hasArray(new String[]{"a", "b", "c"}); // assertion will fail assertThat(atomicArray).hasArray(new String[]{"a", "b", "c", "d"});
- Parameters:
expected
- the array expected to be in the actual AtomicReferenceArray.- Returns:
this
assertion object.- Throws:
AssertionError
- if the AtomicReferenceArray does not have the given array.- Since:
- 2.7.0 / 3.7.0
-
hasOnlyOneElementSatisfying
public AtomicReferenceArrayAssert<T> hasOnlyOneElementSatisfying(Consumer<? super T> elementAssertions)
Verifies that the unique element of theAtomicReferenceArray
satisfies the given assertions expressed as aConsumer
, if it does not, only the first error is reported, useSoftAssertions
to get all the errors.Example:
AtomicReferenceArray<Jedi> jedis = new AtomicReferenceArray<>(new Jedi[]{ new Jedi("Yoda", "red") }); // assertions will pass assertThat(jedis).hasOnlyOneElementSatisfying(yoda -> assertThat(yoda.getName()).startsWith("Y")); assertThat(jedis).hasOnlyOneElementSatisfying(yoda -> { assertThat(yoda.getName()).isEqualTo("Yoda"); assertThat(yoda.getLightSaberColor()).isEqualTo("red"); }); // assertions will fail assertThat(jedis).hasOnlyOneElementSatisfying(yoda -> assertThat(yoda.getName()).startsWith("Vad")); // fail as one the assertions is not satisfied assertThat(jedis).hasOnlyOneElementSatisfying(yoda -> { assertThat(yoda.getName()).isEqualTo("Yoda"); assertThat(yoda.getLightSaberColor()).isEqualTo("purple"); }); // fail but only report the first error assertThat(jedis).hasOnlyOneElementSatisfying(yoda -> { assertThat(yoda.getName()).isEqualTo("Luke"); assertThat(yoda.getLightSaberColor()).isEqualTo("green"); }); // fail and reports the errors thanks to Soft assertions assertThat(jedis).hasOnlyOneElementSatisfying(yoda -> { SoftAssertions softly = new SoftAssertions(); softly.assertThat(yoda.getName()).isEqualTo("Luke"); softly.assertThat(yoda.getLightSaberColor()).isEqualTo("green"); softly.assertAll(); }); // even if the assertion is correct, there are too many jedis ! jedis = new AtomicReferenceArray<>(new Jedi[]{ new Jedi("Yoda", "red"), new Jedi("Luke", "green") }); assertThat(jedis).hasOnlyOneElementSatisfying(yoda -> assertThat(yoda.getName()).startsWith("Yo"));
- Specified by:
hasOnlyOneElementSatisfying
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
elementAssertions
- the assertions to perform on the unique element.- Returns:
this
assertion object.- Throws:
AssertionError
- if theIterable
does not have a unique element.AssertionError
- if theIterable
's unique element does not satisfies the given assertions.- Since:
- 3.12.0
-
hasSize
public AtomicReferenceArrayAssert<T> hasSize(int expected)
Verifies that the number of values in the AtomicReferenceArray is equal to the given one.Example:
AtomicReferenceArray<String> atomicArray = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); assertThat(atomicArray).hasSize(3); // assertion will fail assertThat(atomicArray).hasSize(1);
- Specified by:
hasSize
in interfaceEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
expected
- the expected number of values in the actual AtomicReferenceArray.- Returns:
this
assertion object.- Throws:
AssertionError
- if the number of values of the AtomicReferenceArray is not equal to the given one.- Since:
- 2.7.0 / 3.7.0
-
hasSizeGreaterThan
public AtomicReferenceArrayAssert<T> hasSizeGreaterThan(int boundary)
Verifies that the number of values in the actual array is greater than the given boundary.Example:
AtomicReferenceArray atomicReferenceArray = new AtomicReferenceArray(new String[] { "a", "b", "c" }); // assertion will pass assertThat(atomicReferenceArray).hasSizeGreaterThan(1); // assertion will fail assertThat(atomicReferenceArray).hasSizeGreaterThan(3);
- Specified by:
hasSizeGreaterThan
in interfaceEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
boundary
- the given value to compare the actual size to.- Returns:
this
assertion object.- Throws:
AssertionError
- if the number of values of the actual array is not greater than the boundary.- Since:
- 3.12.0
-
hasSizeGreaterThanOrEqualTo
public AtomicReferenceArrayAssert<T> hasSizeGreaterThanOrEqualTo(int boundary)
Verifies that the number of values in the actual array is greater than or equal to the given boundary.Example:
AtomicReferenceArray atomicReferenceArray = new AtomicReferenceArray(new String[] { "a", "b", "c" }); // assertion will pass assertThat(atomicReferenceArray).hasSizeGreaterThanOrEqualTo(3); // assertion will fail assertThat(atomicReferenceArray).hasSizeGreaterThanOrEqualTo(5);
- Specified by:
hasSizeGreaterThanOrEqualTo
in interfaceEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
boundary
- the given value to compare the actual size to.- Returns:
this
assertion object.- Throws:
AssertionError
- if the number of values of the actual array is not greater than or equal to the boundary.- Since:
- 3.12.0
-
hasSizeLessThan
public AtomicReferenceArrayAssert<T> hasSizeLessThan(int boundary)
Verifies that the number of values in the actual array is less than the given boundary.Example:
AtomicReferenceArray atomicReferenceArray = new AtomicReferenceArray(new String[] { "a", "b", "c" }); // assertion will pass assertThat(atomicReferenceArray).hasSizeLessThan(4); // assertion will fail assertThat(atomicReferenceArray).hasSizeLessThan(2);
- Specified by:
hasSizeLessThan
in interfaceEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
boundary
- the given value to compare the actual size to.- Returns:
this
assertion object.- Throws:
AssertionError
- if the number of values of the actual array is not less than the boundary.- Since:
- 3.12.0
-
hasSizeLessThanOrEqualTo
public AtomicReferenceArrayAssert<T> hasSizeLessThanOrEqualTo(int boundary)
Verifies that the number of values in the actual array is less than or equal to the given boundary.Example:
AtomicReferenceArray atomicReferenceArray = new AtomicReferenceArray(new String[] { "a", "b", "c" }); // assertion will pass assertThat(atomicReferenceArray).hasSizeLessThanOrEqualTo(3); // assertion will fail assertThat(atomicReferenceArray).hasSizeLessThanOrEqualTo(2);
- Specified by:
hasSizeLessThanOrEqualTo
in interfaceEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
boundary
- the given value to compare the actual size to.- Returns:
this
assertion object.- Throws:
AssertionError
- if the number of values of the actual array is not less than or equal to the boundary.- Since:
- 3.12.0
-
hasSizeBetween
public AtomicReferenceArrayAssert<T> hasSizeBetween(int lowerBoundary, int higherBoundary)
Verifies that the number of values in the actual array is between the given boundaries (inclusive).Example:
AtomicReferenceArray atomicReferenceArray = new AtomicReferenceArray(new String[] { "a", "b", "c" }); // assertion will pass assertThat(atomicReferenceArray).hasSizeBetween(3, 4); // assertion will fail assertThat(atomicReferenceArray).hasSizeBetween(4, 6);
- Specified by:
hasSizeBetween
in interfaceEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
lowerBoundary
- the lower boundary compared to which actual size should be greater than or equal to.higherBoundary
- the higher boundary compared to which actual size should be less than or equal to.- Returns:
this
assertion object.- Throws:
AssertionError
- if the number of values of the actual array is not between the boundaries.- Since:
- 3.12.0
-
hasSameSizeAs
public AtomicReferenceArrayAssert<T> hasSameSizeAs(Object other)
Verifies that the actual AtomicReferenceArray has the same size as the given array.Parameter is declared as Object to accept both
Object[]
and primitive arrays (e.g.int[]
).Example:
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); int[] fourFiveSix = {4, 5, 6}; int[] sevenEight = {7, 8}; // assertion will pass assertThat(abc).hasSameSizeAs(fourFiveSix); // assertion will fail assertThat(abc).hasSameSizeAs(sevenEight);
- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
other
- the array to compare size with actual AtomicReferenceArray.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the array parameter isnull
or is not a true array.AssertionError
- if actual AtomicReferenceArray and given array don't have the same size.- Since:
- 2.7.0 / 3.7.0
-
hasSameSizeAs
public AtomicReferenceArrayAssert<T> hasSameSizeAs(Iterable<?> other)
Verifies that the actual AtomicReferenceArray has the same size as the givenIterable
.Example:
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya); // assertion will pass assertThat(abc).hasSameSizeAs(elvesRings); // assertion will fail assertThat(abc).hasSameSizeAs(Arrays.asList("a", "b"));
- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
other
- theIterable
to compare size with actual AtomicReferenceArray.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the otherIterable
isnull
.AssertionError
- if actual AtomicReferenceArray and givenIterable
don't have the same size.- Since:
- 2.7.0 / 3.7.0
-
contains
@SafeVarargs public final AtomicReferenceArrayAssert<T> contains(T... values)
Verifies that the actual AtomicReferenceArray contains the given values, in any order.Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); // assertions will pass assertThat(abc).contains("b", "a") .contains("b", "a", "b"); // assertions will fail assertThat(abc).contains("d"); assertThat(abc).contains("c", "d");
- Specified by:
contains
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray does not contain the given values.- Since:
- 2.7.0 / 3.7.0
-
containsForProxy
protected AtomicReferenceArrayAssert<T> containsForProxy(T[] values)
-
containsOnly
@SafeVarargs public final AtomicReferenceArrayAssert<T> containsOnly(T... values)
Verifies that the actual AtomicReferenceArray 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)..Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); // assertions will pass assertThat(abc).containsOnly("c", "b", "a") .containsOnly("a", "a", "b", "c", "c"); // assertion will fail because "c" is missing from the given values assertThat(abc).containsOnly("a", "b"); // assertion will fail because abc does not contain "d" assertThat(abc).containsOnly("a", "b", "c", "d");
- Specified by:
containsOnly
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray does not contain the given values, i.e. the actual AtomicReferenceArray contains some or none of the given values, or the actual AtomicReferenceArray contains more values than the given ones.- Since:
- 2.7.0 / 3.7.0
-
containsOnlyForProxy
protected AtomicReferenceArrayAssert<T> containsOnlyForProxy(T[] values)
-
containsOnlyElementsOf
public AtomicReferenceArrayAssert<T> containsOnlyElementsOf(Iterable<? extends T> iterable)
Same semantic ascontainsOnly(Object[])
: verifies that actual contains all elements of the givenIterable
and nothing else, in any order and ignoring duplicates (i.e. once a value is found, its duplicates are also considered found).Example :
AtomicReferenceArray<Ring> rings = new AtomicReferenceArray<>(new Ring[]{nenya, vilya}); // assertions will pass assertThat(rings).containsOnlyElementsOf(newArrayList(nenya, vilya)) .containsOnlyElementsOf(newArrayList(nenya, nenya, vilya, vilya)); // assertion will fail as actual does not contain narya assertThat(rings).containsOnlyElementsOf(newArrayList(nenya, vilya, narya)); // assertion will fail as actual contains nenya assertThat(rings).containsOnlyElementsOf(newArrayList(vilya));
- Specified by:
containsOnlyElementsOf
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
iterable
- the givenIterable
we will get elements from.- Returns:
this
assertion object.- Since:
- 2.7.0 / 3.7.0
-
containsOnlyNulls
public AtomicReferenceArrayAssert<T> containsOnlyNulls()
Verifies that the actual AtomicReferenceArray contains only null elements and nothing else.Example :
// assertion will pass AtomicReferenceArray<String> items = new AtomicReferenceArray<>(new String[]{null, null, null}); assertThat(items).containsOnlyNulls(); // assertion will fail because items2 contains not null element AtomicReferenceArray<String> items2 = new AtomicReferenceArray<>(new String[]{null, null, "notNull"}); assertThat(items2).containsOnlyNulls(); // assertion will fail since an empty array does not contain any elements and therefore no null ones. AtomicReferenceArray<String> empty = new AtomicReferenceArray<>(new String[0]); assertThat(empty).containsOnlyNulls();
- Specified by:
containsOnlyNulls
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray is empty or contains non null elements.- Since:
- 2.9.0 / 3.9.0
-
hasSameElementsAs
public AtomicReferenceArrayAssert<T> hasSameElementsAs(Iterable<? extends T> iterable)
An alias ofcontainsOnlyElementsOf(Iterable)
: verifies that actual contains all elements of the givenIterable
and nothing else, in any order.Example:
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{vilya, nenya, narya}); // assertions will pass: assertThat(elvesRings).hasSameElementsAs(newArrayList(nenya, narya, vilya)) .hasSameElementsAs(newArrayList(nenya, narya, vilya, nenya)); // assertions will fail: assertThat(elvesRings).hasSameElementsAs(newArrayList(nenya, narya)); assertThat(elvesRings).hasSameElementsAs(newArrayList(nenya, narya, vilya, oneRing));
- Specified by:
hasSameElementsAs
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
iterable
- theIterable
whose elements we expect to be present- Returns:
- this assertion object
- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
NullPointerException
- if the givenIterable
isnull
AssertionError
- if the actualIterable
does not have the same elements, in any order, as the givenIterable
- Since:
- 2.7.0 / 3.7.0
-
containsOnlyOnce
@SafeVarargs public final AtomicReferenceArrayAssert<T> containsOnlyOnce(T... values)
Verifies that the actual AtomicReferenceArray contains the given values only once.Examples :
// array is a factory method to create arrays. AtomicReferenceArray<String> got = new AtomicReferenceArray<>(new String[]{"winter", "is", "coming"}); // assertions will pass assertThat(got).containsOnlyOnce("winter") .containsOnlyOnce("coming", "winter"); // assertions will fail AtomicReferenceArray<String> stark= new AtomicReferenceArray<>(new String[]{"Arya", "Stark", "daughter", "of", "Ned", "Stark")}); assertThat(got).containsOnlyOnce("Lannister"); assertThat(stark).containsOnlyOnce("Stark");
- Specified by:
containsOnlyOnce
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray does not contain the given values, i.e. the actual AtomicReferenceArray contains some or none of the given values, or the actual AtomicReferenceArray contains more than once these values.- Since:
- 2.7.0 / 3.7.0
-
containsOnlyOnceForProxy
protected AtomicReferenceArrayAssert<T> containsOnlyOnceForProxy(T[] values)
-
containsOnlyOnceElementsOf
public AtomicReferenceArrayAssert<T> containsOnlyOnceElementsOf(Iterable<? extends T> iterable)
Same semantic asObjectEnumerableAssert.containsOnlyOnce(Object...)
: verifies that the actual group contains the elements of the given iterable only once.Examples :
// assertions will pass assertThat(list("winter", "is", "coming")).containsOnlyOnceElementsOf(list("winter")) .containsOnlyOnceElementsOf(list("coming", "winter")); // assertions will fail assertThat(list("winter", "is", "coming")).containsOnlyOnceElementsOf(list("Lannister")); assertThat(list("Arya", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnceElementsOf(list("Stark")); assertThat(list("Arya", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnceElementsOf(list("Stark", "Lannister", "Arya"));
If you want to directly specify the elements to check with, use
ObjectEnumerableAssert.containsOnlyOnce(Object...)
instead.- Specified by:
containsOnlyOnceElementsOf
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
iterable
- the givenIterable
we will get elements from.- Returns:
this
assertion object.
-
containsExactly
@SafeVarargs public final AtomicReferenceArrayAssert<T> containsExactly(T... values)
Verifies that the actual AtomicReferenceArray contains only the given values and nothing else, in order.
Example :
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{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:
containsExactly
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray does not contain the given values with same order, i.e. the actual AtomicReferenceArray contains some or none of the given values, or the actual AtomicReferenceArray contains more values than the given ones or values are the same but the order is not.- Since:
- 2.7.0 / 3.7.0
-
containsExactlyForProxy
protected AtomicReferenceArrayAssert<T> containsExactlyForProxy(T[] values)
-
containsExactlyInAnyOrder
@SafeVarargs public final AtomicReferenceArrayAssert<T> containsExactlyInAnyOrder(T... values)
Verifies that the actual AtomicReferenceArray contains exactly the given values and nothing else, in any order.
Example :
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{vilya, nenya, narya}); // assertion will pass assertThat(elvesRings).containsExactlyInAnyOrder(vilya, vilya, nenya, narya); // assertion will fail as vilya is contained twice in elvesRings. assertThat(elvesRings).containsExactlyInAnyOrder(nenya, vilya, narya);
- Specified by:
containsExactlyInAnyOrder
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the actual group isnull
.AssertionError
- if the actual AtomicReferenceArray does not contain the given values, i.e. it contains some or none of the given values, or more values than the given ones.
-
containsExactlyInAnyOrderForProxy
protected AtomicReferenceArrayAssert<T> containsExactlyInAnyOrderForProxy(T[] values)
-
containsExactlyInAnyOrderElementsOf
public AtomicReferenceArrayAssert<T> containsExactlyInAnyOrderElementsOf(Iterable<? extends T> values)
Verifies that the actual AtomicReferenceArray contains exactly the given values and nothing else, in any order.
Example :
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray(new Ring[]{vilya, nenya, narya, vilya}); AtomicReferenceArray<Ring> elvesRingsSomeMissing = new AtomicReferenceArray(new Ring[]{vilya, nenya, narya}); AtomicReferenceArray<Ring> elvesRingsDifferentOrder = new AtomicReferenceArray(new Ring[]{nenya, narya, vilya, vilya}); // assertion will pass assertThat(elvesRings).containsExactlyInAnyOrder(elvesRingsDifferentOrder); // assertion will fail as vilya is contained twice in elvesRings. assertThat(elvesRings).containsExactlyInAnyOrder(elvesRingsSomeMissing);
- Specified by:
containsExactlyInAnyOrderElementsOf
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the actual group isnull
.AssertionError
- if the actual group does not contain the given values, i.e. the actual group contains some or none of the given values, or the actual group contains more values than the given ones.- Since:
- 2.9.0 / 3.9.0
-
containsExactlyElementsOf
public AtomicReferenceArrayAssert<T> containsExactlyElementsOf(Iterable<? extends T> iterable)
Same ascontainsExactly(Object...)
but handles theIterable
to array conversion : verifies that actual contains all elements of the givenIterable
and nothing else in the same order.Example :
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{vilya, nenya, narya}); // assertion will pass assertThat(elvesRings).containsExactlyElementsOf(newLinkedList(vilya, nenya, narya)); // assertion will fail as actual and expected order differ assertThat(elvesRings).containsExactlyElementsOf(newLinkedList(nenya, vilya, narya));
- Specified by:
containsExactlyElementsOf
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
iterable
- the givenIterable
we will get elements from.- Returns:
this
assertion object.
-
containsSequence
@SafeVarargs public final AtomicReferenceArrayAssert<T> containsSequence(T... sequence)
Verifies that the actual AtomicReferenceArray contains the given sequence in the correct order and without extra values between the sequence values.Use
containsSubsequence(Object...)
to allow values between the expected sequence values.Example:
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{vilya, nenya, narya}); // assertion will pass assertThat(elvesRings).containsSequence(vilya, nenya) .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:
containsSequence
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
sequence
- the sequence of objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the given array isnull
.AssertionError
- if the actual AtomicReferenceArray does not contain the given sequence.
-
containsSequenceForProxy
protected AtomicReferenceArrayAssert<T> containsSequenceForProxy(T[] sequence)
-
containsSequence
public AtomicReferenceArrayAssert<T> containsSequence(Iterable<? extends T> sequence)
Verifies that the actual AtomicReferenceArray contains the given sequence in the correct order and without extra values between the sequence values.Use
containsSubsequence(Object...)
to allow values between the expected sequence values.Example:
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{vilya, nenya, narya}); // assertion will pass assertThat(elvesRings).containsSequence(newArrayList(vilya, nenya)) .containsSequence(newArrayList(nenya, narya)); // assertions will fail, the elements order is correct but there is a value between them (nenya) assertThat(elvesRings).containsSequence(newArrayList(vilya, narya)); assertThat(elvesRings).containsSequence(newArrayList(nenya, vilya));
- Specified by:
containsSequence
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
sequence
- the sequence of objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the given array isnull
.AssertionError
- if the actual AtomicReferenceArray does not contain the given sequence.
-
doesNotContainSequence
@SafeVarargs public final AtomicReferenceArrayAssert<T> doesNotContainSequence(T... sequence)
Verifies that the actual AtomicReferenceArray contains the given sequence in the given order and without extra values between the sequence values.Use
doesNotContainSubsequence(Object...)
to also ensure the sequence does not exist with values between the expected sequence values.Example:
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{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:
doesNotContainSequence
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
sequence
- the sequence of objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the given array isnull
.AssertionError
- if the actual AtomicReferenceArray does not contain the given sequence.
-
doesNotContainSequenceForProxy
protected AtomicReferenceArrayAssert<T> doesNotContainSequenceForProxy(T[] sequence)
-
doesNotContainSequence
public AtomicReferenceArrayAssert<T> doesNotContainSequence(Iterable<? extends T> sequence)
Verifies that the actual AtomicReferenceArray contains the given sequence in the given order and without extra values between the sequence values.Use
doesNotContainSubsequence(Iterable)
to also ensure the sequence does not exist with values between the expected sequence values.Example:
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{vilya, nenya, narya}); // assertion will pass, the elements order is correct but there is a value between them (nenya) assertThat(elvesRings).containsSequence(newArrayList(vilya, narya)); assertThat(elvesRings).containsSequence(newArrayList(nenya, vilya)); // assertions will fail assertThat(elvesRings).containsSequence(newArrayList(vilya, nenya)); assertThat(elvesRings).containsSequence(newArrayList(nenya, narya));
- Specified by:
doesNotContainSequence
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
sequence
- the sequence of objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the given array isnull
.AssertionError
- if the actual AtomicReferenceArray does not contain the given sequence.
-
containsSubsequence
@SafeVarargs public final AtomicReferenceArrayAssert<T> containsSubsequence(T... subsequence)
Verifies that the actual AtomicReferenceArray contains the given subsequence in the correct order (possibly with other values between them).Example:
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{vilya, nenya, narya}); // assertions will pass assertThat(elvesRings).containsSubsequence(vilya, nenya) .containsSubsequence(vilya, narya); // assertion will fail assertThat(elvesRings).containsSubsequence(nenya, vilya);
- Specified by:
containsSubsequence
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
subsequence
- the subsequence of objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the given array isnull
.AssertionError
- if the actual AtomicReferenceArray does not contain the given subsequence.
-
containsSubsequenceForProxy
protected AtomicReferenceArrayAssert<T> containsSubsequenceForProxy(T[] subsequence)
-
containsSubsequence
public AtomicReferenceArrayAssert<T> containsSubsequence(Iterable<? extends T> subsequence)
Verifies that the actual AtomicReferenceArray contains the given subsequence in the correct order (possibly with other values between them).Example:
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{vilya, nenya, narya}); // assertions will pass assertThat(elvesRings).containsSubsequence(newArrayList(vilya, nenya)) .containsSubsequence(newArrayList(vilya, narya)); // assertion will fail assertThat(elvesRings).containsSubsequence(newArrayList(nenya, vilya));
- Specified by:
containsSubsequence
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
subsequence
- the subsequence of objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the given array isnull
.AssertionError
- if the actual AtomicReferenceArray does not contain the given subsequence.
-
doesNotContainSubsequence
@SafeVarargs public final AtomicReferenceArrayAssert<T> doesNotContainSubsequence(T... subsequence)
Verifies that the actual AtomicReferenceArray does not contain the given subsequence in the correct order (possibly with other values between them).Example:
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{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:
doesNotContainSubsequence
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
subsequence
- the subsequence of objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the given array isnull
.AssertionError
- if the actual AtomicReferenceArray contains the given subsequence.
-
doesNotContainSubsequenceForProxy
protected AtomicReferenceArrayAssert<T> doesNotContainSubsequenceForProxy(T[] subsequence)
-
doesNotContainSubsequence
public AtomicReferenceArrayAssert<T> doesNotContainSubsequence(Iterable<? extends T> subsequence)
Verifies that the actual AtomicReferenceArray does not contain the given subsequence in the correct order (possibly with other values between them).Example:
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{vilya, nenya, narya}); // assertions will pass assertThat(elvesRings).doesNotContainSubsequence(newArrayList(nenya, vilya)); // assertion will fail assertThat(elvesRings).doesNotContainSubsequence(newArrayList(vilya, nenya)); assertThat(elvesRings).doesNotContainSubsequence(newArrayList(vilya, narya));
- Specified by:
doesNotContainSubsequence
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
subsequence
- the subsequence of objects to look for.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the given array isnull
.AssertionError
- if the actual AtomicReferenceArray contains the given subsequence.
-
contains
public AtomicReferenceArrayAssert<T> contains(T value, Index index)
Verifies that the actual AtomicReferenceArray contains the given object at the given index.Example:
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{vilya, nenya, narya}); // assertions will pass assertThat(elvesRings).contains(vilya, atIndex(0)) .contains(nenya, atIndex(1)) .contains(narya, atIndex(2)); // assertions will fail assertThat(elvesRings).contains(vilya, atIndex(1)); assertThat(elvesRings).contains(nenya, atIndex(2)); assertThat(elvesRings).contains(narya, atIndex(0));
- Specified by:
contains
in interfaceIndexedObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
value
- the object to look for.index
- the index where the object should be stored in the actual AtomicReferenceArray.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
or empty.NullPointerException
- if the givenIndex
isnull
.IndexOutOfBoundsException
- if the value of the givenIndex
is equal to or greater than the size of the actual AtomicReferenceArray.AssertionError
- if the actual AtomicReferenceArray does not contain the given object at the given index.
-
hasOnlyElementsOfTypes
public AtomicReferenceArrayAssert<T> hasOnlyElementsOfTypes(Class<?>... types)
Verifies that all elements of the actual group are instances of given classes or interfaces.Example :
AtomicReferenceArray<Object> elvesRings = new AtomicReferenceArray<>(new Object[]{"", new StringBuilder()}); // assertions will pass assertThat(objects).hasOnlyElementsOfTypes(CharSequence.class); assertThat(objects).hasOnlyElementsOfTypes(String.class, StringBuilder.class); // assertions will fail assertThat(objects).hasOnlyElementsOfTypes(Number.class); assertThat(objects).hasOnlyElementsOfTypes(String.class, Number.class); assertThat(objects).hasOnlyElementsOfTypes(String.class);
- Specified by:
hasOnlyElementsOfTypes
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
types
- the expected classes and interfaces- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the actual group isnull
.AssertionError
- if not all elements of the actual group are instances of one of the given types- Since:
- 2.7.0 / 3.7.0
-
hasExactlyElementsOfTypes
public AtomicReferenceArrayAssert<T> hasExactlyElementsOfTypes(Class<?>... expectedTypes)
Verifies that the actual elements are of the given types in the given order, there should be as many expected types as there are actual elements.Example:
AtomicReferenceArray<Object> objects = new AtomicReferenceArray<>(new Object[] { 1, "a", 1.00 }); // assertion succeeds assertThat(objects).hasExactlyElementsOfTypes(Integer.class, String.class, String.class, Double.class); // assertions fail // missing second String type assertThat(objects).hasExactlyElementsOfTypes(Integer.class, String.class, Double.class); // no Float type in actual assertThat(objects).hasExactlyElementsOfTypes(Float.class, String.class, String.class, Double.class); // correct types but wrong order assertThat(objects).hasExactlyElementsOfTypes(String.class, Integer.class, String.class, Double.class); // actual has more elements than the specified expected types assertThat(objects).hasExactlyElementsOfTypes(String.class);
- Specified by:
hasExactlyElementsOfTypes
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
expectedTypes
- the expected types- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given type array isnull
.AssertionError
- if actual isnull
.AssertionError
- if the actual elements types don't exactly match the given ones (in the given order).
-
doesNotContain
public AtomicReferenceArrayAssert<T> doesNotContain(T value, Index index)
Verifies that the actual AtomicReferenceArray does not contain the given object at the given index.Example:
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{vilya, nenya, narya}); // assertions will pass assertThat(elvesRings).doesNotContain(vilya, atIndex(1)) .doesNotContain(nenya, atIndex(2)) .doesNotContain(narya, atIndex(0)); // assertions will fail assertThat(elvesRings).doesNotContain(vilya, atIndex(0)); assertThat(elvesRings).doesNotContain(nenya, atIndex(1)); assertThat(elvesRings).doesNotContain(narya, atIndex(2));
- Specified by:
doesNotContain
in interfaceIndexedObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
value
- the object to look for.index
- the index where the object should not be stored in the actual AtomicReferenceArray.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.NullPointerException
- if the givenIndex
isnull
.AssertionError
- if the actual AtomicReferenceArray contains the given object at the given index.
-
doesNotContain
@SafeVarargs public final AtomicReferenceArrayAssert<T> doesNotContain(T... values)
Verifies that the actual AtomicReferenceArray does not contain the given values.Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"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:
doesNotContain
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray contains any of the given values.
-
doesNotContainForProxy
protected AtomicReferenceArrayAssert<T> doesNotContainForProxy(T[] values)
-
doesNotContainAnyElementsOf
public AtomicReferenceArrayAssert<T> doesNotContainAnyElementsOf(Iterable<? extends T> iterable)
Verifies that the actual AtomicReferenceArray does not contain any elements of the givenIterable
(i.e. none).Example:
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); // assertion will pass assertThat(actual).doesNotContainAnyElementsOf(newArrayList("d", "e")); // assertions will fail assertThat(actual).doesNotContainAnyElementsOf(newArrayList("a", "b")); assertThat(actual).doesNotContainAnyElementsOf(newArrayList("d", "e", "a"));
- Specified by:
doesNotContainAnyElementsOf
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
iterable
- theIterable
whose elements must not be in the actual AtomicReferenceArray.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.IllegalArgumentException
- if the given argument is an empty iterable.AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray contains some elements of the givenIterable
.
-
doesNotHaveDuplicates
public AtomicReferenceArrayAssert<T> doesNotHaveDuplicates()
Verifies that the actual AtomicReferenceArray does not contain duplicates.Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); AtomicReferenceArray<String> aaa = new AtomicReferenceArray<>(new String[]{"a", "a", "a"}); // assertion will pass assertThat(abc).doesNotHaveDuplicates(); // assertion will fail assertThat(aaa).doesNotHaveDuplicates();
- Specified by:
doesNotHaveDuplicates
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray contains duplicates.
-
startsWith
@SafeVarargs public final AtomicReferenceArrayAssert<T> startsWith(T... sequence)
Verifies that the actual AtomicReferenceArray 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 the first element of the actual AtomicReferenceArray.containsSequence(Object...)
Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); // assertion will pass assertThat(abc).startsWith("a", "b"); // assertion will fail assertThat(abc).startsWith("c");
- Specified by:
startsWith
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
sequence
- the sequence of objects to look for.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given argument isnull
.IllegalArgumentException
- if the given argument is an empty array.AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray does not start with the given sequence of objects.
-
startsWithForProxy
protected AtomicReferenceArrayAssert<T> startsWithForProxy(T[] sequence)
-
endsWith
@SafeVarargs public final AtomicReferenceArrayAssert<T> endsWith(T first, T... sequence)
Verifies that the actual AtomicReferenceArray 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 AtomicReferenceArray.containsSequence(Object...)
Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); // assertion will pass assertThat(abc).endsWith("b", "c"); // assertion will fail assertThat(abc).endsWith("a");
- Specified by:
endsWith
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
first
- the first element of the end sequence of objects to look for.sequence
- the rest of the end sequence of objects to look for.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray does not end with the given sequence of objects.
-
endsWithForProxy
protected AtomicReferenceArrayAssert<T> endsWithForProxy(T first, T[] sequence)
-
endsWith
public AtomicReferenceArrayAssert<T> endsWith(T[] sequence)
Verifies that the actual AtomicReferenceArray 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 AtomicReferenceArray.containsSequence(Object...)
Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); // assertions will pass assertThat(abc).endsWith(new String[0]) .endsWith(new String[] {"b", "c"}); // assertion will fail assertThat(abc).endsWith(new String[] {"a"});
- Specified by:
endsWith
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
sequence
- the (possibly empty) sequence of objects to look for.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray does not end with the given sequence of objects.
-
isSubsetOf
public AtomicReferenceArrayAssert<T> isSubsetOf(Iterable<? extends T> values)
Verifies that all elements of actual are present in the givenIterable
.Example:
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{vilya, nenya, narya}); List<Ring> ringsOfPower = newArrayList(oneRing, vilya, nenya, narya, dwarfRing, manRing); // assertion will pass: assertThat(elvesRings).isSubsetOf(ringsOfPower); // assertion will fail: assertThat(elvesRings).isSubsetOf(newArrayList(nenya, narya));
- Specified by:
isSubsetOf
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
values
- theIterable
that should contain all actual elements.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualIterable
isnull
.NullPointerException
- if the givenIterable
isnull
.AssertionError
- if the actualIterable
is not subset of setIterable
.
-
isSubsetOf
@SafeVarargs public final AtomicReferenceArrayAssert<T> isSubsetOf(T... values)
Verifies that all elements of actual are present in the given values.Example:
AtomicReferenceArray<Ring> elvesRings = new AtomicReferenceArray<>(new Ring[]{vilya, nenya, narya}); // assertions will pass: assertThat(elvesRings).isSubsetOf(vilya, nenya, narya) .isSubsetOf(vilya, nenya, narya, dwarfRing); // assertions will fail: assertThat(elvesRings).isSubsetOf(vilya, nenya); assertThat(elvesRings).isSubsetOf(vilya, nenya, dwarfRing);
- Specified by:
isSubsetOf
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
values
- the values that should be used for checking the elements of actual.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the actualIterable
isnull
.AssertionError
- if the actualIterable
is not subset of the given values.
-
isSubsetOfForProxy
protected AtomicReferenceArrayAssert<T> isSubsetOfForProxy(T[] values)
-
containsNull
public AtomicReferenceArrayAssert<T> containsNull()
Verifies that the actual AtomicReferenceArray contains at least a null element.Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); AtomicReferenceArray<String> abNull = new AtomicReferenceArray<>(new String[]{"a", "b", null}); // assertion will pass assertThat(abNull).containsNull(); // assertion will fail assertThat(abc).containsNull();
- Specified by:
containsNull
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray does not contain a null element.
-
doesNotContainNull
public AtomicReferenceArrayAssert<T> doesNotContainNull()
Verifies that the actual AtomicReferenceArray does not contain null elements.Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); AtomicReferenceArray<String> abNull = new AtomicReferenceArray<>(new String[]{"a", "b", null}); // assertion will pass assertThat(abc).doesNotContainNull(); // assertion will fail assertThat(abNull).doesNotContainNull();
- Specified by:
doesNotContainNull
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray contains a null element.
-
are
public AtomicReferenceArrayAssert<T> are(Condition<? super T> condition)
Verifies that each element value satisfies the given conditionExample :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); AtomicReferenceArray<String> abcc = new AtomicReferenceArray<>(new String[]{"a", "b", "cc"}); Condition<String> singleCharacterString = new Condition<>(s -> s.length() == 1, "single character String"); // assertion will pass assertThat(abc).are(singleCharacterString); // assertion will fail assertThat(abcc).are(singleCharacterString);
- Specified by:
are
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
condition
- the given condition.- Returns:
this
object.- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if an element cannot be cast to T.AssertionError
- if one or more elements don't satisfy the given condition.
-
areNot
public AtomicReferenceArrayAssert<T> areNot(Condition<? super T> condition)
Verifies that each element value does not satisfy the given conditionExample :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); AtomicReferenceArray<String> abcc = new AtomicReferenceArray<>(new String[]{"a", "b", "cc"}); Condition<String> moreThanOneCharacter = = new Condition<>(s -> s.length() > 1, "more than one character"); // assertion will pass assertThat(abc).areNot(moreThanOneCharacter); // assertion will fail assertThat(abcc).areNot(moreThanOneCharacter);
- Specified by:
areNot
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
condition
- the given condition.- Returns:
this
object.- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if an element cannot be cast to T.AssertionError
- if one or more elements satisfy the given condition.
-
have
public AtomicReferenceArrayAssert<T> have(Condition<? super T> condition)
Verifies that all elements satisfy the given condition.Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); AtomicReferenceArray<String> abcc = new AtomicReferenceArray<>(new String[]{"a", "b", "cc"}); Condition<String> onlyOneCharacter = = new Condition<>(s -> s.length() == 1, "only one character"); // assertion will pass assertThat(abc).have(onlyOneCharacter); // assertion will fail assertThat(abcc).have(onlyOneCharacter);
- Specified by:
have
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
condition
- the given condition.- Returns:
this
object.- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if an element cannot be cast to T.AssertionError
- if one or more elements do not satisfy the given condition.
-
doNotHave
public AtomicReferenceArrayAssert<T> doNotHave(Condition<? super T> condition)
Verifies that all elements don't satisfy the given condition.Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); AtomicReferenceArray<String> abcc = new AtomicReferenceArray<>(new String[]{"a", "b", "cc"}); Condition<String> moreThanOneCharacter = = new Condition<>(s -> s.length() > 1, "more than one character"); // assertion will pass assertThat(abc).doNotHave(moreThanOneCharacter); // assertion will fail assertThat(abcc).doNotHave(moreThanOneCharacter);
- Specified by:
doNotHave
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
condition
- the given condition.- Returns:
this
object.- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if an element cannot be cast to T.AssertionError
- if one or more elements satisfy the given condition.
-
areAtLeast
public AtomicReferenceArrayAssert<T> areAtLeast(int times, Condition<? super T> condition)
Verifies that there are at least n elements in the actual AtomicReferenceArray satisfying the given condition.Example :
AtomicReferenceArray<Integer> oneTwoThree = new AtomicReferenceArray<>(new Integer[]{1, 2, 3}); Condition<Integer> oddNumber = new Condition<>(value % 2 == 1, "odd number"); // assertion will pass oneTwoThree.areAtLeast(2, oddNumber); // assertion will fail oneTwoThree.areAtLeast(3, oddNumber);
- Specified by:
areAtLeast
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
times
- the minimum number of times the condition should be verified.condition
- the given condition.- Returns:
this
object.- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if an element can not be cast to T.AssertionError
- if the number of elements satisfying the given condition is < n.
-
areAtLeastOne
public AtomicReferenceArrayAssert<T> areAtLeastOne(Condition<? super T> condition)
Verifies that there is at least one element in the actual AtomicReferenceArray satisfying the given condition.This method is an alias for
areAtLeast(1, condition)
.Example:
// jedi is a Condition<String> AtomicReferenceArray<String> rebels = new AtomicReferenceArray<>(new String[]{"Luke", "Solo", "Leia"}); assertThat(rebels).areAtLeastOne(jedi);
- Specified by:
areAtLeastOne
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
condition
- the given condition.- Returns:
this
assertion object.- See Also:
haveAtLeast(int, Condition)
-
areAtMost
public AtomicReferenceArrayAssert<T> areAtMost(int times, Condition<? super T> condition)
Verifies that there are at most n elements in the actual AtomicReferenceArray satisfying the given condition.Example :
AtomicReferenceArray<Integer> oneTwoThree = new AtomicReferenceArray<>(new Integer[]{1, 2, 3}); Condition<Integer> oddNumber = new Condition<>(value % 2 == 1, "odd number"); // assertions will pass oneTwoThree.areAtMost(2, oddNumber); oneTwoThree.areAtMost(3, oddNumber); // assertion will fail oneTwoThree.areAtMost(1, oddNumber);
- Specified by:
areAtMost
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
times
- the number of times the condition should be at most verified.condition
- the given condition.- Returns:
this
object.- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if an element cannot be cast to T.AssertionError
- if the number of elements satisfying the given condition is > n.
-
areExactly
public AtomicReferenceArrayAssert<T> areExactly(int times, Condition<? super T> condition)
Verifies that there are exactly n elements in the actual AtomicReferenceArray satisfying the given condition.Example :
AtomicReferenceArray<Integer> oneTwoThree = new AtomicReferenceArray<>(new Integer[]{1, 2, 3}); Condition<Integer> oddNumber = new Condition<>(value % 2 == 1, "odd number"); // assertion will pass oneTwoThree.areExactly(2, oddNumber); // assertions will fail oneTwoThree.areExactly(1, oddNumber); oneTwoThree.areExactly(3, oddNumber);
- Specified by:
areExactly
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
times
- the exact number of times the condition should be verified.condition
- the given condition.- Returns:
this
object.- Throws:
NullPointerException
- if the given condition isnull
.AssertionError
- if an element cannot be cast to T.AssertionError
- if the number of elements satisfying the given condition is ≠ n.
-
haveAtLeastOne
public AtomicReferenceArrayAssert<T> haveAtLeastOne(Condition<? super T> condition)
Verifies that there is at least one element in the actual AtomicReferenceArray satisfying the given condition.This method is an alias for
haveAtLeast(1, condition)
.Example:
AtomicReferenceArray<BasketBallPlayer> bullsPlayers = new AtomicReferenceArray<>(new BasketBallPlayer[]{butler, rose}); // potentialMvp is a Condition<BasketBallPlayer> assertThat(bullsPlayers).haveAtLeastOne(potentialMvp);
- Specified by:
haveAtLeastOne
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
condition
- the given condition.- Returns:
this
assertion object.- See Also:
haveAtLeast(int, Condition)
-
haveAtLeast
public AtomicReferenceArrayAssert<T> haveAtLeast(int times, Condition<? super T> condition)
Verifies that there are at least n elements in the actual AtomicReferenceArray satisfying the given condition.Example :
This method is an alias forAtomicReferenceArray<Integer> oneTwoThree = new AtomicReferenceArray<>(new Integer[]{1, 2, 3}); Condition<Integer> oddNumber = new Condition<>(value % 2 == 1, "odd number"); // assertion will pass oneTwoThree.haveAtLeast(2, oddNumber); // assertion will fail oneTwoThree.haveAtLeast(3, oddNumber);
areAtLeast(int, Condition)
.- Specified by:
haveAtLeast
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
times
- the minimum number of times the condition must hold.condition
- the given condition.- Returns:
this
assertion object.
-
haveAtMost
public AtomicReferenceArrayAssert<T> haveAtMost(int times, Condition<? super T> condition)
Verifies that there are at most n elements in the actual AtomicReferenceArray satisfying the given condition.Example :
This method is an aliasAtomicReferenceArray<Integer> oneTwoThree = new AtomicReferenceArray<>(new Integer[]{1, 2, 3}); Condition<Integer> oddNumber = new Condition<>(value % 2 == 1, "odd number"); // assertions will pass oneTwoThree.haveAtMost(2, oddNumber); oneTwoThree.haveAtMost(3, oddNumber); // assertion will fail oneTwoThree.haveAtMost(1, oddNumber);
areAtMost(int, Condition)
.- Specified by:
haveAtMost
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
times
- the maximum number of times the condition must hold.condition
- the given condition.- Returns:
this
assertion object.
-
haveExactly
public AtomicReferenceArrayAssert<T> haveExactly(int times, Condition<? super T> condition)
Verifies that there are exactly n elements in the actual AtomicReferenceArray satisfying the given condition.Example :
This method is an aliasAtomicReferenceArray<Integer> oneTwoThree = new AtomicReferenceArray<>(new Integer[]{1, 2, 3}); Condition<Integer> oddNumber = new Condition<>(value % 2 == 1, "odd number"); // assertion will pass oneTwoThree.haveExactly(2, oddNumber); // assertions will fail oneTwoThree.haveExactly(1, oddNumber); oneTwoThree.haveExactly(3, oddNumber);
areExactly(int, Condition)
.- Specified by:
haveExactly
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
times
- the exact number of times the condition must hold.condition
- the given condition.- Returns:
this
assertion object.
-
hasAtLeastOneElementOfType
public AtomicReferenceArrayAssert<T> hasAtLeastOneElementOfType(Class<?> expectedType)
Verifies that at least one element in the actual AtomicReferenceArray has the specified type (matching includes subclasses of the given type).Example:
AtomicReferenceArray<Number> numbers = new AtomicReferenceArray<>(new Number[]{ 2, 6L, 8.0 }); // successful assertion: assertThat(numbers).hasAtLeastOneElementOfType(Long.class); // assertion failure: assertThat(numbers).hasAtLeastOneElementOfType(Float.class);
- Specified by:
hasAtLeastOneElementOfType
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
expectedType
- the expected type.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given type isnull
.AssertionError
- if the actual AtomicReferenceArray does not have any elements of the given type.
-
hasOnlyElementsOfType
public AtomicReferenceArrayAssert<T> hasOnlyElementsOfType(Class<?> expectedType)
Verifies that all the elements in the actual AtomicReferenceArray belong to the specified type (matching includes subclasses of the given type).Example:
AtomicReferenceArray<Number> numbers = new AtomicReferenceArray<>(new Number[]{ 2, 6, 8 }); // successful assertion: assertThat(numbers).hasOnlyElementsOfType(Integer.class); // assertion failure: assertThat(numbers).hasOnlyElementsOfType(Long.class);
- Specified by:
hasOnlyElementsOfType
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
expectedType
- the expected type.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given type isnull
.AssertionError
- if one element is not of the expected type.
-
doesNotHaveAnyElementsOfTypes
public AtomicReferenceArrayAssert<T> doesNotHaveAnyElementsOfTypes(Class<?>... unexpectedTypes)
Verifies that all the elements in the actual AtomicReferenceArray do not belong to the specified types (including subclasses).Example:
AtomicReferenceArray<Number> numbers = new AtomicReferenceArray<>(new Number[]{ 2, 6, 8.0 }); // successful assertion: assertThat(numbers).doesNotHaveAnyElementsOfTypes(Long.class, Float.class); // assertion failure: assertThat(numbers).doesNotHaveAnyElementsOfTypes(Long.class, Integer.class);
- Specified by:
doesNotHaveAnyElementsOfTypes
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
unexpectedTypes
- the not expected types.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given types isnull
.AssertionError
- if one element's type matches the given types.- Since:
- 2.9.0 / 3.9.0
-
isSorted
public AtomicReferenceArrayAssert<T> isSorted()
Verifies that the actual array is sorted in 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<AtomicReferenceArrayAssert<T>,T>
- Returns:
this
assertion object.
-
isSortedAccordingTo
public AtomicReferenceArrayAssert<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 the element is compatible with comparator, otherwise an AssertionError is thrown.- Specified by:
isSortedAccordingTo
in interfaceArraySortedAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
comparator
- theComparator
used to compare array elements- Returns:
this
assertion object.
-
containsAll
public AtomicReferenceArrayAssert<T> containsAll(Iterable<? extends T> iterable)
Verifies that the actual AtomicReferenceArray contains all the elements of givenIterable
, in any order.Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); // assertion will pass assertThat(abc).containsAll(Arrays.asList("b", "c")); // assertions will fail assertThat(abc).containsAll(Arrays.asList("d")); assertThat(abc).containsAll(Arrays.asList("a", "b", "c", "d"));
- Specified by:
containsAll
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
iterable
- the givenIterable
we will get elements from.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the actual AtomicReferenceArray isnull
.AssertionError
- if the actual AtomicReferenceArray does not contain all the elements of givenIterable
.
-
usingElementComparator
public AtomicReferenceArrayAssert<T> usingElementComparator(Comparator<? super T> elementComparator)
Use given custom comparator instead of relying on actual element typeequals
method to compare AtomicReferenceArray 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(invoiceArray).usingComparator(invoicePayeeComparator).isEqualTo(expectedinvoiceArray). // compares invoices by date, doesNotHaveDuplicates and contains both use the given invoice date comparator assertThat(invoiceArray).usingComparator(invoiceDateComparator).doesNotHaveDuplicates().contains(may2010Invoice) // as assertThat(invoiceArray) creates a new assertion, it falls back to standard comparison strategy // based on Invoice's equal method to compare invoiceArray elements to lowestInvoice. assertThat(invoiceArray).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<AtomicReferenceArrayAssert<T>,T>
- Parameters:
elementComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given comparator isnull
.
-
usingExtendedByTypesElementComparator
private AtomicReferenceArrayAssert<T> usingExtendedByTypesElementComparator(Comparator<Object> elementComparator)
-
usingDefaultElementComparator
public AtomicReferenceArrayAssert<T> 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<AtomicReferenceArrayAssert<T>,T>
- Returns:
this
assertion object.
-
usingComparatorForElementFieldsWithNames
@Deprecated public <C> AtomicReferenceArrayAssert<T> usingComparatorForElementFieldsWithNames(Comparator<C> comparator, String... elementPropertyOrFieldNames)
Deprecated.This method is used withusingFieldByFieldElementComparator()
which is deprecated in favor ofusingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration)
orAbstractAssert.usingRecursiveComparison()
.When using
AbstractAssert.usingRecursiveComparison()
the equivalent is:RecursiveComparisonAssert.withEqualsForFields(java.util.function.BiPredicate, String...)
RecursiveComparisonAssert.withComparatorForFields(Comparator, String...)
and when using
RecursiveComparisonConfiguration
:Deprecated javadocAllows to set a comparator to compare properties or fields of elements with the given names. A typical usage is for comparing fields of numeric type at a given precision.
To be used, comparators need to be specified by this method before calling any of:
usingFieldByFieldElementComparator()
usingElementComparatorOnFields(String...)
usingElementComparatorIgnoringFields(String...)
Comparators specified by this method have precedence over comparators specified by
usingComparatorForElementFieldsWithType
.Example:
public class TolkienCharacter { private String name; private double height; // constructor omitted } TolkienCharacter frodo = new TolkienCharacter("Frodo", 1.2); TolkienCharacter tallerFrodo = new TolkienCharacter("Frodo", 1.3); TolkienCharacter reallyTallFrodo = new TolkienCharacter("Frodo", 1.9); Comparator<Double> closeEnough = new Comparator<Double>() { double precision = 0.5; public int compare(Double d1, Double d2) { return Math.abs(d1 - d2) <= precision ? 0 : 1; } }; AtomicReferenceArray<TolkienCharacter> hobbits = new AtomicReferenceArray<>(new TolkienCharacter[]{frodo}); // assertions will pass assertThat(hobbits).usingComparatorForElementFieldsWithNames(closeEnough, "height") .usingFieldByFieldElementComparator() .contains(tallerFrodo); assertThat(hobbits).usingComparatorForElementFieldsWithNames(closeEnough, "height") .usingElementComparatorOnFields("height") .contains(tallerFrodo); assertThat(hobbits).usingComparatorForElementFieldsWithNames(closeEnough, "height") .usingElementComparatorIgnoringFields("name") .contains(tallerFrodo); assertThat(hobbits).usingComparatorForElementFieldsWithNames(closeEnough, "height") .usingRecursiveFieldByFieldElementComparator() .contains(tallerFrodo); // assertion will fail assertThat(hobbits).usingComparatorForElementFieldsWithNames(closeEnough, "height") .usingFieldByFieldElementComparator() .containsExactly(reallyTallFrodo);
- Type Parameters:
C
- the type to compare.- Parameters:
comparator
- theComparator
to useelementPropertyOrFieldNames
- the names of the properties and/or fields of the elements the comparator should be used for- Returns:
this
assertions object- Since:
- 2.7.0 / 3.7.0
-
usingComparatorForElementFieldsWithType
@Deprecated public <C> AtomicReferenceArrayAssert<T> usingComparatorForElementFieldsWithType(Comparator<C> comparator, Class<C> type)
Deprecated.This method is used withusingFieldByFieldElementComparator()
which is deprecated in favor ofusingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration)
orAbstractAssert.usingRecursiveComparison()
.When using
AbstractAssert.usingRecursiveComparison()
the equivalent is:RecursiveComparisonAssert.withEqualsForType(java.util.function.BiPredicate, Class)
RecursiveComparisonAssert.withComparatorForType(Comparator, Class)
and when using
RecursiveComparisonConfiguration
:Deprecated javadocAllows to set a specific comparator to compare properties or fields of elements with the given type. A typical usage is for comparing fields of numeric type at a given precision.
To be used, comparators need to be specified by this method before calling any of:
usingFieldByFieldElementComparator()
usingElementComparatorOnFields(String...)
usingElementComparatorIgnoringFields(String...)
Comparators specified by
usingComparatorForElementFieldsWithNames
have precedence over comparators specified by this method.Example:
If multiple compatible comparators have been registered for a givenpublic class TolkienCharacter { private String name; private double height; // constructor omitted } TolkienCharacter frodo = new TolkienCharacter("Frodo", 1.2); TolkienCharacter tallerFrodo = new TolkienCharacter("Frodo", 1.3); TolkienCharacter reallyTallFrodo = new TolkienCharacter("Frodo", 1.9); Comparator<Double> closeEnough = new Comparator<Double>() { double precision = 0.5; public int compare(Double d1, Double d2) { return Math.abs(d1 - d2) <= precision ? 0 : 1; } }; AtomicReferenceArray<TolkienCharacter> hobbits = new AtomicReferenceArray<>(new TolkienCharacter[]{frodo}); // assertions will pass assertThat(hobbits).usingComparatorForElementFieldsWithType(closeEnough, Double.class) .usingFieldByFieldElementComparator() .contains(tallerFrodo); assertThat(hobbits).usingComparatorForElementFieldsWithType(closeEnough, Double.class) .usingElementComparatorOnFields("height") .contains(tallerFrodo); assertThat(hobbits).usingComparatorForElementFieldsWithType(closeEnough, Double.class) .usingElementComparatorIgnoringFields("name") .contains(tallerFrodo); assertThat(hobbits).usingComparatorForElementFieldsWithType(closeEnough, Double.class) .usingRecursiveFieldByFieldElementComparator() .contains(tallerFrodo); // assertion will fail assertThat(hobbits).usingComparatorForElementFieldsWithType(closeEnough, Double.class) .usingFieldByFieldElementComparator() .contains(reallyTallFrodo);
type
, the closest in the inheritance chain to the giventype
is chosen in the following order:- The comparator for the exact given
type
- The comparator of a superclass of the given
type
- The comparator of an interface implemented by the given
type
- Type Parameters:
C
- the type to compare.- Parameters:
comparator
- theComparator
to usetype
- theClass
of the type of the element fields the comparator should be used for- Returns:
this
assertions object- Since:
- 2.7.0 / 3.7.0
-
usingComparatorForType
public <C> AtomicReferenceArrayAssert<T> usingComparatorForType(Comparator<C> comparator, Class<C> type)
Allows to set a specific comparator for the given type of elements or their fields. ExtendsusingComparatorForElementFieldsWithType(java.util.Comparator<C>, java.lang.Class<C>)
by applying comparator specified for given type to elements themselves, not only to their fields.Usage of this method affects comparators set by next methods:
usingFieldByFieldElementComparator()
usingElementComparatorOnFields(String...)
usingElementComparatorIgnoringFields(String...)
Example:
// assertion will pass assertThat(new AtomicReferenceArray<>(new Object[] { "some", new BigDecimal("4.2") })) .usingComparatorForType(BIG_DECIMAL_COMPARATOR, BigDecimal.class) .contains(new BigDecimal("4.20"));
- Type Parameters:
C
- the type to compare.- Parameters:
comparator
- theComparator
to usetype
- theClass
of the type of the element or element fields the comparator should be used for- Returns:
this
assertions object- Since:
- 2.9.0 / 3.9.0
-
usingFieldByFieldElementComparator
@Deprecated public AtomicReferenceArrayAssert<T> usingFieldByFieldElementComparator()
Deprecated.This method is deprecated because it performs a shallow field by field comparison, i.e. elements are compared field by field but the fields are compared with equals, useusingRecursiveFieldByFieldElementComparator()
orAbstractAssert.usingRecursiveComparison()
instead to perform a true recursive comparison.
See https://assertj.github.io/doc/#assertj-core-recursive-comparisonDeprecated javadocUse field/property by field/property comparison (including inherited fields/properties) instead of relying on actual type A
equals
method to compare AtomicReferenceArray elements for incoming assertion checks. Private fields are included but this can be disabled usingAssertions.setAllowExtractingPrivateFields(boolean)
.This can be handy if
equals
method of the objects to compare does not suit you.You can specify a custom comparator per name or type of element field with
usingComparatorForElementFieldsWithNames(Comparator, String...)
andusingComparatorForElementFieldsWithType(Comparator, Class)
.Note that the comparison is not recursive, if one of the fields/properties is an Object, it will be compared to the other field/property using its
Example:equals
method.TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT); TolkienCharacter frodoClone = new TolkienCharacter("Frodo", 33, HOBBIT); // Fail if equals has not been overridden in TolkienCharacter as equals default implementation only compares references assertThat(atomicArray(frodo)).contains(frodoClone); // frodo and frodoClone are equals when doing a field by field comparison. assertThat(atomicArray(frodo)).usingFieldByFieldElementComparator().contains(frodoClone);
- Returns:
this
assertion object.- Since:
- 2.7.0 / 3.7.0
-
usingRecursiveFieldByFieldElementComparator
public AtomicReferenceArrayAssert<T> usingRecursiveFieldByFieldElementComparator()
Enable using a recursive field by field comparison strategy similar toAbstractAssert.usingRecursiveComparison()
but contrary to the latter you can chain any iterable assertions after this method (this is why this method exists).This method uses the default
RecursiveComparisonConfiguration
, if you need to customize it useusingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration)
instead.Breaking change: since 3.20.0 the comparison won't use any comparators set with:
usingComparatorForType(Comparator, Class)
usingComparatorForElementFieldsWithType(Comparator, Class)
usingComparatorForElementFieldsWithNames(Comparator, String...)
These features (and many more) are provided through
usingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration)
with a customizedRecursiveComparisonConfiguration
where there methods are called:registerComparatorForType(Comparator, Class)
/withComparatorForType(Comparator, Class)
(usingRecursiveComparisonConfiguration.Builder
)registerEqualsForType(BiPredicate, Class)
/withComparatorForType(Comparator, Class)
(usingRecursiveComparisonConfiguration.Builder
)registerComparatorForFields(Comparator comparator, String... fields)
/withComparatorForField(Comparator comparator, String... fields)
(usingRecursiveComparisonConfiguration.Builder
)
There are differences between this approach and
AbstractAssert.usingRecursiveComparison()
:- contrary to
RecursiveComparisonAssert
, you can chain any iterable assertions after this method. - no comparators registered with
AbstractIterableAssert.usingComparatorForType(Comparator, Class)
will be used, you need to register them in the configuration object. - the assertion errors won't be as detailed as
RecursiveComparisonAssert.isEqualTo(Object)
which shows the field differences.
This last point makes sense, take the
contains(Object...)
assertion, it would not be relevant to report the differences of all the iterable's elements differing from the values to look for.Example:
public class Person { String name; boolean hasPhd; } public class Doctor { String name; boolean hasPhd; } Doctor drSheldon = new Doctor("Sheldon Cooper", true); Doctor drLeonard = new Doctor("Leonard Hofstadter", true); Doctor drRaj = new Doctor("Raj Koothrappali", true); Person sheldon = new Person("Sheldon Cooper", true); Person leonard = new Person("Leonard Hofstadter", true); Person raj = new Person("Raj Koothrappali", true); Person howard = new Person("Howard Wolowitz", true); AtomicReferenceArray<Doctor> doctors = new AtomicReferenceArray<>(array(drSheldon, drLeonard, drRaj)); AtomicReferenceArray<Person> persons = new AtomicReferenceArray<>(array(sheldon, leonard, raj)); // assertion succeeds as both lists contains equivalent items in order. assertThat(doctors).usingRecursiveFieldByFieldElementComparator() .contains(sheldon); // assertion fails because leonard names are different. leonard.setName("Leonard Ofstater"); assertThat(doctors).usingRecursiveFieldByFieldElementComparator() .contains(leonard); // assertion fails because howard is missing and leonard is not expected. people = list(howard, sheldon, raj) assertThat(doctors).usingRecursiveFieldByFieldElementComparator() .contains(howard);
Another point worth mentioning: elements order does matter if the expected iterable is ordered, for example comparing a
Set<Person>
to aList<Person>
fails asList
is ordered andSet
is not.
The ordering can be ignored by callingignoringCollectionOrder
allowing ordered/unordered iterable comparison, note thatignoringCollectionOrder
is applied recursively on any nested iterable fields, if this behavior is too generic, use the more fine grainedignoringCollectionOrderInFields
orignoringCollectionOrderInFieldsMatchingRegexes
.- Returns:
this
assertion object.- Since:
- 2.7.0 / 3.7.0 - breaking change in 3.20.0
- See Also:
RecursiveComparisonConfiguration
,usingRecursiveFieldByFieldElementComparator(org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration)
-
usingRecursiveFieldByFieldElementComparator
public AtomicReferenceArrayAssert<T> usingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration configuration)
Enable using a recursive field by field comparison strategy similar toAbstractAssert.usingRecursiveComparison()
but contrary to the latter you can chain any iterable assertions after this method (this is why this method exists).The given
RecursiveComparisonConfiguration
is used to tweak the comparison behavior, for example byignoring collection order
.Warning: the comparison won't use any comparators set with:
usingComparatorForType(Comparator, Class)
usingComparatorForElementFieldsWithType(Comparator, Class)
usingComparatorForElementFieldsWithNames(Comparator, String...)
These features (and many more) are provided through
RecursiveComparisonConfiguration
with:registerComparatorForType(Comparator, Class)
/withComparatorForType(Comparator, Class)
(usingRecursiveComparisonConfiguration.Builder
)registerEqualsForType(BiPredicate, Class)
/withComparatorForType(Comparator, Class)
(usingRecursiveComparisonConfiguration.Builder
)registerComparatorForFields(Comparator comparator, String... fields)
/withComparatorForField(Comparator comparator, String... fields)
(usingRecursiveComparisonConfiguration.Builder
)
RecursiveComparisonConfiguration exposes a
builder
to ease setting the comparison behaviour, callRecursiveComparisonConfiguration.builder()
to start building your configuration.There are differences between this approach and
AbstractAssert.usingRecursiveComparison()
:- contrary to
RecursiveComparisonAssert
, you can chain any iterable assertions after this method. - no comparators registered with
AbstractIterableAssert.usingComparatorForType(Comparator, Class)
will be used, you need to register them in the configuration object. - the assertion errors won't be as detailed as
RecursiveComparisonAssert.isEqualTo(Object)
which shows the field differences.
This last point makes sense, take the
contains(Object...)
assertion, it would not be relevant to report the differences of all the iterable's elements differing from the values to look for.Example:
A detailed documentation for the recursive comparison is available here: https://assertj.github.io/doc/#assertj-core-recursive-comparison.public class Person { String name; boolean hasPhd; } public class Doctor { String name; boolean hasPhd; } Doctor drSheldon = new Doctor("Sheldon Cooper", true); Doctor drLeonard = new Doctor("Leonard Hofstadter", true); Doctor drRaj = new Doctor("Raj Koothrappali", true); Person sheldon = new Person("Sheldon Cooper", false); Person leonard = new Person("Leonard Hofstadter", false); Person raj = new Person("Raj Koothrappali", false); Person howard = new Person("Howard Wolowitz", false); AtomicReferenceArray<Doctor> doctors = new AtomicReferenceArray<>(array(drSheldon, drLeonard, drRaj)); AtomicReferenceArray<Person> persons = new AtomicReferenceArray<>(array(sheldon, leonard, raj)); RecursiveComparisonConfiguration configuration = RecursiveComparisonConfiguration.builder() .withIgnoredFields​("hasPhd"); // assertion succeeds as both lists contains equivalent items in order. assertThat(doctors).usingRecursiveFieldByFieldElementComparator(configuration) .contains(sheldon); // assertion fails because leonard names are different. leonard.setName("Leonard Ofstater"); assertThat(doctors).usingRecursiveFieldByFieldElementComparator(configuration) .contains(leonard); // assertion fails because howard is missing and leonard is not expected. people = list(howard, sheldon, raj) assertThat(doctors).usingRecursiveFieldByFieldElementComparator(configuration) .contains(howard);
A point worth mentioning: elements order does matter if the expected iterable is ordered, for example comparing a
Set<Person>
to aList<Person>
fails asList
is ordered andSet
is not.
The ordering can be ignored by callingignoringCollectionOrder
allowing ordered/unordered iterable comparison, note thatignoringCollectionOrder
is applied recursively on any nested iterable fields, if this behavior is too generic, use the more fine grainedignoringCollectionOrderInFields
orignoringCollectionOrderInFieldsMatchingRegexes
.- Parameters:
configuration
- the recursive comparison configuration.- Returns:
this
assertion object.- Since:
- 3.20.0
- See Also:
RecursiveComparisonConfiguration
-
usingElementComparatorOnFields
@Deprecated public AtomicReferenceArrayAssert<T> usingElementComparatorOnFields(String... fields)
Deprecated.This method is deprecated because it performs a shallow field by field comparison, i.e. elements are compared field by field but the fields are compared with equals, useusingRecursiveFieldByFieldElementComparatorOnFields(String...)
instead.
See https://assertj.github.io/doc/#assertj-core-recursive-comparisonDeprecated javadocUse field/property by field/property comparison on the given fields/properties only (including inherited fields/properties) instead of relying on actual type A
equals
method to compare AtomicReferenceArray elements for incoming assertion checks. Private fields are included but this can be disabled usingAssertions.setAllowExtractingPrivateFields(boolean)
.This can be handy if
equals
method of the objects to compare does not suit you.You can specify a custom comparator per name or type of element field with
usingComparatorForElementFieldsWithNames(Comparator, String...)
andusingComparatorForElementFieldsWithType(Comparator, Class)
.Note that the comparison is not recursive, if one of the fields/properties is an Object, it will be compared to the other field/property using its
Example:equals
method.TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT); TolkienCharacter sam = new TolkienCharacter("Sam", 38, HOBBIT); // frodo and sam both are hobbits, so they are equals when comparing only race assertThat(atomicArray(frodo)).usingElementComparatorOnFields("race").contains(sam); // OK // ... but not when comparing both name and race assertThat(atomicArray(frodo)).usingElementComparatorOnFields("name", "race").contains(sam); // FAIL
- Parameters:
fields
- the fields to compare field/property by field/property.- Returns:
this
assertion object.- Since:
- 2.7.0 / 3.7.0
- See Also:
usingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration)
, https://assertj.github.io/doc/#assertj-core-recursive-comparison
-
usingRecursiveFieldByFieldElementComparatorOnFields
public AtomicReferenceArrayAssert<T> usingRecursiveFieldByFieldElementComparatorOnFields(String... fields)
The assertions chained after this method will use a recursive field by field comparison on the given fields (including inherited fields) instead of relying on the elementequals
method. This is handy when the elementequals
method is not overridden or implemented as you expect.Nested fields are supported and are expressed like:
name.first
The comparison is recursive: elements are compared field by field, if a field type has fields they are also compared field by field (and so on).
Example:
Player derrickRose = new Player(new Name("Derrick", "Rose"), "Chicago Bulls"); derrickRose.nickname = new Name("Crazy", "Dunks"); Player jalenRose = new Player(new Name("Jalen", "Rose"), "Chicago Bulls"); jalenRose.nickname = new Name("Crazy", "Defense"); // assertion succeeds as all compared fields match assertThat(atomicArray(derrickRose)).usingRecursiveFieldByFieldElementComparatorOnFields("name.last", "team", "nickname.first") .contains(jalenRose); // assertion fails, name.first values differ assertThat(atomicArray(derrickRose)).usingRecursiveFieldByFieldElementComparatorOnFields("name") .contains(jalenRose);
This method is actually a shortcut of
usingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration)
with a configuration comparing only the given fields, the previous example can be written as:
The recursive comparison is documented here: https://assertj.github.io/doc/#assertj-core-recursive-comparisonRecursiveComparisonConfiguration configuration = RecursiveComparisonConfiguration.builder() .withComparedFields("name.last", "team", "nickname.first") .build(); assertThat(atomicArray(derrickRose)).usingRecursiveFieldByFieldElementComparator(configuration) .contains(jalenRose);
- Parameters:
fields
- the field names to exclude in the elements comparison.- Returns:
this
assertion object.- Since:
- 3.20.0
- See Also:
usingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration)
, https://assertj.github.io/doc/#assertj-core-recursive-comparison
-
usingElementComparatorIgnoringFields
@Deprecated public AtomicReferenceArrayAssert<T> usingElementComparatorIgnoringFields(String... fields)
Deprecated.This method is deprecated because it performs a shallow field by field comparison, i.e. elements are compared field by field but the fields are compared with equals, useusingRecursiveFieldByFieldElementComparatorIgnoringFields(String...)
instead.
See https://assertj.github.io/doc/#assertj-core-recursive-comparisonDeprecated javadocUse field/property by field/property on all fields/properties except the given ones (including inherited fields/properties) instead of relying on actual type A
equals
method to compare AtomicReferenceArray elements for incoming assertion checks. Private fields are included but this can be disabled usingAssertions.setAllowExtractingPrivateFields(boolean)
.This can be handy if
equals
method of the objects to compare does not suit you.You can specify a custom comparator per name or type of element field with
usingComparatorForElementFieldsWithNames(Comparator, String...)
andusingComparatorForElementFieldsWithType(Comparator, Class)
.Note that the comparison is not recursive, if one of the fields/properties is an Object, it will be compared to the other field/property using its
Example:equals
method.TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT); TolkienCharacter sam = new TolkienCharacter("Sam", 38, HOBBIT); // frodo and sam both are hobbits, so they are equals when comparing only race (i.e. ignoring all other fields) assertThat(atomicArray(frodo)).usingElementComparatorIgnoringFields("name", "age").contains(sam); // OK // ... but not when comparing both name and race assertThat(atomicArray(frodo)).usingElementComparatorIgnoringFields("age").contains(sam); // FAIL
- Parameters:
fields
- the names of the fields/properties to ignore- Returns:
this
assertion object.- Since:
- 2.7.0 / 3.7.0
- See Also:
usingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration)
, https://assertj.github.io/doc/#assertj-core-recursive-comparison
-
usingRecursiveFieldByFieldElementComparatorIgnoringFields
public AtomicReferenceArrayAssert<T> usingRecursiveFieldByFieldElementComparatorIgnoringFields(String... fields)
The assertions chained after this method will use a recursive field by field comparison on all fields (including inherited fields) except the given ones instead of relying on the elementequals
method. This is handy when the elementequals
method is not overridden or implemented as you expect.Nested fields are supported and are expressed like:
name.first
The comparison is recursive: elements are compared field by field, if a field type has fields they are also compared field by field (and so on).
Example:
Player derrickRose = new Player(new Name("Derrick", "Rose"), "Chicago Bulls"); derrickRose.nickname = new Name("Crazy", "Dunks"); Player jalenRose = new Player(new Name("Jalen", "Rose"), "Chicago Bulls"); jalenRose.nickname = new Name("Crazy", "Defense"); // assertion succeeds assertThat(atomicArray(derrickRose)).usingRecursiveFieldByFieldElementComparatorIgnoringFields("name.first", "nickname.last") .contains(jalenRose); // assertion fails, names are ignored but nicknames are not and nickname.last values differ assertThat(atomicArray(derrickRose)).usingRecursiveFieldByFieldElementComparatorIgnoringFields("name") .contains(jalenRose);
This method is actually a shortcut of
usingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration)
with a configuration ignoring the given fields, the previous example can be written as:
The recursive comparison is documented here: https://assertj.github.io/doc/#assertj-core-recursive-comparisonRecursiveComparisonConfiguration configuration = RecursiveComparisonConfiguration.builder() .withIgnoredFields("name.first", "nickname.last") .build(); assertThat(atomicArray(derrickRose)).usingRecursiveFieldByFieldElementComparator(configuration) .contains(jalenRose);
- Parameters:
fields
- the field names to exclude in the elements comparison.- Returns:
this
assertion object.- Since:
- 3.20.0
- See Also:
usingRecursiveFieldByFieldElementComparator(RecursiveComparisonConfiguration)
, https://assertj.github.io/doc/#assertj-core-recursive-comparison
-
extracting
public 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.It allows you to test a field/property of the array's elements instead of testing the elements themselves, which can be much less work !
Let's take an example to make things clearer :
A property with the given name is looked for first, if it does not exist then a field with the given name is looked for.// 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. AtomicReferenceArray<TolkienCharacter> fellowshipOfTheRing = new AtomicReferenceArray<>(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");
Note that the order of extracted field/property values is consistent with the array order.
- Parameters:
fieldOrProperty
- the field/property to extract from the array under test- Returns:
- a new assertion object whose object under test is the array of extracted field/property values.
- Throws:
IntrospectionError
- if no field or property exists with the given name- Since:
- 2.7.0 / 3.7.0
-
extracting
public <P> ObjectArrayAssert<P> extracting(String fieldOrProperty, Class<P> extractingType)
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 with type.It allows you to test a field/property of the array's elements instead of testing the elements themselves, which can be much less work !
Let's take an example to make things clearer :
A property with the given name is looked for first, if it does not exist then a field with the given name is looked for.// 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. AtomicReferenceArray<TolkienCharacter> fellowshipOfTheRing = new AtomicReferenceArray<>(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", String.class) .contains("Boromir", "Gandalf", "Frodo") .doesNotContain("Sauron", "Elrond"); // you can also extract nested field/property like the name of Race : assertThat(fellowshipOfTheRing).extracting("race.name", String.class) .contains("Hobbit", "Elf") .doesNotContain("Orc");
Note that the order of extracted field/property values is consistent with the order of the array under test.
- Type Parameters:
P
- the extracted type- Parameters:
fieldOrProperty
- the field/property to extract from the array under testextractingType
- type to return- Returns:
- a new assertion object whose object under test is the array of extracted field/property values.
- Throws:
IntrospectionError
- if no field or property exists with the given name- Since:
- 2.7.0 / 3.7.0
-
extracting
public ObjectArrayAssert<Tuple> extracting(String... propertiesOrFields)
Extract the values of given fields/properties from the array's elements under test into a new array composed of Tuple (a simple data structure), this new array becoming the array under test.It allows you to test fields/properties of the array's elements instead of testing the elements themselves, it can be sometimes much less work !
The Tuple data corresponds to the extracted values of the given fields/properties, for instance if you ask to extract "id", "name" and "email" then each Tuple data will be composed of id, name and email extracted from the element of the initial array (the Tuple's data order is the same as the given fields/properties order).
Let's take an example to make things clearer :
A property with the given name is looked for first, if it does not exist the a field with the given name is looked for.// 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. AtomicReferenceArray<TolkienCharacter> fellowshipOfTheRing = new AtomicReferenceArray<>(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' and 'age' of some TolkienCharacter in fellowshipOfTheRing : assertThat(fellowshipOfTheRing).extracting("name", "age") .contains(tuple("Boromir", 37), tuple("Sam", 38), tuple("Legolas", 1000)); // extract 'name', 'age' and Race name values. assertThat(fellowshipOfTheRing).extracting("name", "age", "race.name") .contains(tuple("Boromir", 37, "Man"), tuple("Sam", 38, "Hobbit"), tuple("Legolas", 1000, "Elf"));
Note that the order of extracted property/field values is consistent with the iteration order of the array under test.
- Parameters:
propertiesOrFields
- the properties/fields to extract from the initial array under test- Returns:
- a new assertion object whose object under test is the list of Tuple with extracted properties/fields values as data.
- Throws:
IntrospectionError
- if one of the given name does not match a field or property in one of the initial Iterable's element.
-
extracting
public <U> ObjectArrayAssert<U> extracting(Function<? super T,U> extractor)
Extract the values from the array's elements by applying an extracting function on them. The returned array becomes a new object under test.It allows to test values from the elements in safer way than by using
extracting(String)
, as it doesn't utilize introspection.Let's take a look an example:
Note that the order of extracted property/field values is consistent with the iteration order of the Iterable under test, for example if it's a// Build a list of TolkienCharacter, a TolkienCharacter has a name, and age and a Race (a specific class) // they can be public field or properties, both can be extracted. AtomicReferenceArray<TolkienCharacter> fellowshipOfTheRing = new AtomicReferenceArray<>(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) }; // this extracts the race Function<TolkienCharacter, Race> race = new Function<TolkienCharacter, Race>() { @Override public Race extract(TolkienCharacter input) { return input.getRace(); } } // fellowship has hobbits, right, my presioussss? assertThat(fellowshipOfTheRing).extracting(race).contains(HOBBIT);
HashSet
, you won't be able to make any assumptions on the extracted values order.- Type Parameters:
U
- the extracted values type- Parameters:
extractor
- the object transforming input object to desired one- Returns:
- a new assertion object whose object under test is the list of values extracted
- Since:
- 2.7.0 / 3.7.0
-
extracting
public <U,EXCEPTION extends Exception> ObjectArrayAssert<U> extracting(ThrowingExtractor<? super T,U,EXCEPTION> extractor)
Extract the values from the array's elements by applying an extracting function (which might throw an exception) on them. The returned array becomes a new object under test.Any checked exception raised in the extractor is rethrown wrapped in a
RuntimeException
.It allows to test values from the elements in safer way than by using
extracting(String)
, as it doesn't utilize introspection.Let's take a look an example:
Note that the order of extracted property/field values is consistent with the iteration order of the Iterable under test, for example if it's a// Build a list of TolkienCharacter, a TolkienCharacter has a name, and age and a Race (a specific class) // they can be public field or properties, both can be extracted. AtomicReferenceArray<TolkienCharacter> fellowshipOfTheRing = new AtomicReferenceArray<>(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) }; assertThat(fellowshipOfTheRing).extracting(input -> { if (input.getAge() < 20) { throw new Exception("age < 20"); } return input.getName(); }).contains("Frodo");
HashSet
, you won't be able to make any assumptions on the extracted values order.- Type Parameters:
U
- the extracted values typeEXCEPTION
- the exception type- Parameters:
extractor
- the object transforming input object to desired one- Returns:
- a new assertion object whose object under test is the list of values extracted
- Since:
- 3.7.0
-
flatExtracting
public <U,C extends Collection<U>> ObjectArrayAssert<U> flatExtracting(Function<? super T,C> extractor)
Extract the Iterable values from the array's elements by applying an Iterable extracting function on them and concatenating the result lists into an array which becomes the new object under test.It allows testing the results of extracting values that are represented by Iterables.
For example:
The order of extracted values is consisted with both the order of the collection itself, as well as the extracted collections.CartoonCharacter bart = new CartoonCharacter("Bart Simpson"); CartoonCharacter lisa = new CartoonCharacter("Lisa Simpson"); CartoonCharacter maggie = new CartoonCharacter("Maggie Simpson"); CartoonCharacter homer = new CartoonCharacter("Homer Simpson"); homer.addChildren(bart, lisa, maggie); CartoonCharacter pebbles = new CartoonCharacter("Pebbles Flintstone"); CartoonCharacter fred = new CartoonCharacter("Fred Flintstone"); fred.getChildren().add(pebbles); Function<CartoonCharacter, List<CartoonCharacter>> childrenOf = new Function<CartoonCharacter, List<CartoonCharacter>>() { @Override public List<CartoonChildren> extract(CartoonCharacter input) { return input.getChildren(); } } AtomicReferenceArray<CartoonCharacter> parents = new AtomicReferenceArray<>(new CartoonCharacter[]{ homer, fred }); // check children assertThat(parents).flatExtracting(childrenOf) .containsOnly(bart, lisa, maggie, pebbles);
- Type Parameters:
U
- the type of elements to extract.C
- the type of collection to flat/extract.- Parameters:
extractor
- the object transforming input object to an Iterable of desired ones- Returns:
- a new assertion object whose object under test is the list of values extracted
- Since:
- 2.7.0 / 3.7.0
-
flatExtracting
public <U,C extends Collection<U>,EXCEPTION extends Exception> ObjectArrayAssert<U> flatExtracting(ThrowingExtractor<? super T,C,EXCEPTION> extractor)
Extract the Iterable values from the array's elements by applying an Iterable extracting function (which might throw an exception) on them and concatenating the result lists into an array which becomes the new object under test.It allows testing the results of extracting values that are represented by Iterables.
For example:
The order of extracted values is consisted with both the order of the collection itself, as well as the extracted collections.CartoonCharacter bart = new CartoonCharacter("Bart Simpson"); CartoonCharacter lisa = new CartoonCharacter("Lisa Simpson"); CartoonCharacter maggie = new CartoonCharacter("Maggie Simpson"); CartoonCharacter homer = new CartoonCharacter("Homer Simpson"); homer.addChildren(bart, lisa, maggie); CartoonCharacter pebbles = new CartoonCharacter("Pebbles Flintstone"); CartoonCharacter fred = new CartoonCharacter("Fred Flintstone"); fred.getChildren().add(pebbles); AtomicReferenceArray<CartoonCharacter> parents = new AtomicReferenceArray<>(new CartoonCharacter[]{ homer, fred }); // check children assertThat(parents).flatExtracting(input -> { if (input.getChildren().size() == 0) { throw new Exception("no children"); } return input.getChildren(); }).containsOnly(bart, lisa, maggie, pebbles);
- Type Parameters:
U
- the type of elements to extract.C
- the type of collection to flat/extract.EXCEPTION
- the exception type- Parameters:
extractor
- the object transforming input object to an Iterable of desired ones- Returns:
- a new assertion object whose object under test is the list of values extracted
- Since:
- 3.7.0
-
doFlatExtracting
private <U,C extends Collection<U>> ObjectArrayAssert<U> doFlatExtracting(Function<? super T,C> extractor)
-
flatExtracting
public ObjectArrayAssert<Object> flatExtracting(String propertyName)
Extract from array's elements the Iterable/Array values corresponding to the given property/field name and concatenate them into a single array becoming the new object under test.It allows testing the elements of extracting values that are represented by iterables or arrays.
For example:
The order of extracted values is consisted with both the order of the collection itself, as well as the extracted collections.CartoonCharacter bart = new CartoonCharacter("Bart Simpson"); CartoonCharacter lisa = new CartoonCharacter("Lisa Simpson"); CartoonCharacter maggie = new CartoonCharacter("Maggie Simpson"); CartoonCharacter homer = new CartoonCharacter("Homer Simpson"); homer.addChildren(bart, lisa, maggie); CartoonCharacter pebbles = new CartoonCharacter("Pebbles Flintstone"); CartoonCharacter fred = new CartoonCharacter("Fred Flintstone"); fred.getChildren().add(pebbles); AtomicReferenceArray<CartoonCharacter> parents = new AtomicReferenceArray<>(new CartoonCharacter[]{ homer, fred }); // check children assertThat(parents).flatExtracting("children") .containsOnly(bart, lisa, maggie, pebbles);
- Parameters:
propertyName
- the object transforming input object to an Iterable of desired ones- Returns:
- a new assertion object whose object under test is the list of values extracted
- Throws:
IllegalArgumentException
- if one of the extracted property value was not an array or an iterable.- Since:
- 2.7.0 / 3.7.0
-
extractingResultOf
public ObjectArrayAssert<Object> extractingResultOf(String method)
Extract the result of given method invocation from the array's elements under test into a new array, this new array becoming the array under test.It allows you to test a method results of the array's elements instead of testing the elements themselves, which can be much less work!
It is especially useful for classes that does not conform to the Java Bean's getter specification (i.e. public String toString() or public String status() instead of public String getStatus()).
Let's take an example to make things clearer :
// Build a array of WesterosHouse, a WesterosHouse has a method: public String sayTheWords() AtomicReferenceArray<WesterosHouse> greatHousesOfWesteros = new AtomicReferenceArray<>(new WesterosHouse[]{ new WesterosHouse("Stark", "Winter is Coming"), new WesterosHouse("Lannister", "Hear Me Roar!"), new WesterosHouse("Greyjoy", "We Do Not Sow"), new WesterosHouse("Baratheon", "Our is the Fury"), new WesterosHouse("Martell", "Unbowed, Unbent, Unbroken"), new WesterosHouse("Tyrell", "Growing Strong") }); // let's verify the words of the great houses of Westeros: assertThat(greatHousesOfWesteros).extractingResultOf("sayTheWords") .contains("Winter is Coming", "We Do Not Sow", "Hear Me Roar") .doesNotContain("Lannisters always pay their debts");
Following requirements have to be met to extract method results:
- method has to be public,
- method cannot accept any arguments,
- method cannot return void.
Note that the order of extracted values is consistent with the order of the array under test.
- Parameters:
method
- the name of the method which result is to be extracted from the array under test- Returns:
- a new assertion object whose object under test is the array of extracted values.
- Throws:
IllegalArgumentException
- if no method exists with the given name, or method is not public, or method does return void, or method accepts arguments.- Since:
- 2.7.0 / 3.7.0
-
extractingResultOf
public <P> ObjectArrayAssert<P> extractingResultOf(String method, Class<P> extractingType)
Extract the result of given method invocation from the array's elements under test into a new array, this new array becoming the array under test.It allows you to test a method results of the array's elements instead of testing the elements themselves, which can be much less work!
It is especially useful for classes that do not conform to the Java Bean's getter specification (i.e. public String toString() or public String status() instead of public String getStatus()).
Let's take an example to make things clearer :
// Build a array of WesterosHouse, a WesterosHouse has a method: public String sayTheWords() AtomicReferenceArray<WesterosHouse> greatHousesOfWesteros = new AtomicReferenceArray<>(new WesterosHouse[]{ new WesterosHouse("Stark", "Winter is Coming"), new WesterosHouse("Lannister", "Hear Me Roar!"), new WesterosHouse("Greyjoy", "We Do Not Sow"), new WesterosHouse("Baratheon", "Our is the Fury"), new WesterosHouse("Martell", "Unbowed, Unbent, Unbroken"), new WesterosHouse("Tyrell", "Growing Strong") }); // let's verify the words of the great houses of Westeros: assertThat(greatHousesOfWesteros).extractingResultOf("sayTheWords", String.class) .contains("Winter is Coming", "We Do Not Sow", "Hear Me Roar") .doesNotContain("Lannisters always pay their debts");
Following requirements have to be met to extract method results:
- method has to be public,
- method can not accept any arguments,
- method can not return void.
Note that the order of extracted values is consistent with the order of the array under test.
- Type Parameters:
P
- the extracted type- Parameters:
method
- the name of the method which result is to be extracted from the array under testextractingType
- type to return- Returns:
- a new assertion object whose object under test is the array of extracted values.
- Throws:
IllegalArgumentException
- if no method exists with the given name, or method is not public, or method does return void, or method accepts arguments.- Since:
- 2.7.0 / 3.7.0
-
inHexadecimal
public AtomicReferenceArrayAssert<T> inHexadecimal()
Enable hexadecimal object representation of Iterable elements instead of standard java representation in error messages.It can be useful to better understand what the error was with a more meaningful error message.
Example
With standard error message:AtomicReferenceArray<Byte> bytes = new AtomicReferenceArray<>(new Byte[]{ 0x10, 0x20 }); assertThat(bytes).inHexadecimal().contains(new Byte[] { 0x30 });
With Hexadecimal error message:Expecting: <[16, 32]> to contain: <[48]> but could not find: <[48]>
Expecting: <[0x10, 0x20]> to contain: <[0x30]> but could not find: <[0x30]>
- Overrides:
inHexadecimal
in classAbstractAssert<AtomicReferenceArrayAssert<T>,AtomicReferenceArray<T>>
- Returns:
this
assertion object.- Since:
- 2.7.0 / 3.7.0
-
inBinary
public AtomicReferenceArrayAssert<T> inBinary()
Description copied from class:AbstractAssert
Use binary object representation instead of standard representation in error messages.Example:
assertThat(1).inBinary().isEqualTo(2); org.junit.ComparisonFailure: Expected :0b00000000_00000000_00000000_00000010 Actual :0b00000000_00000000_00000000_00000001
- Overrides:
inBinary
in classAbstractAssert<AtomicReferenceArrayAssert<T>,AtomicReferenceArray<T>>
- Returns:
this
assertion object.
-
filteredOn
public AtomicReferenceArrayAssert<T> filteredOn(String propertyOrFieldName, Object expectedValue)
Filter the array under test keeping only elements having a property or field equal toexpectedValue
, the property/field is specified bypropertyOrFieldName
parameter.The filter first tries to get the value from a property (named
propertyOrFieldName
), if no such property exists it tries to read the value from a field. Reading private fields is supported by default, this can be globally disabled by callingAssertions.setAllowExtractingPrivateFields(false)
.When reading nested property/field, if an intermediate value is null the whole nested property/field is considered to be null, thus reading "address.street.name" value will return null if "street" value is null.
As an example, let's check all employees 800 years old (yes, special employees):
Nested properties/fields are supported:Employee yoda = new Employee(1L, new Name("Yoda"), 800); Employee obiwan = new Employee(2L, new Name("Obiwan"), 800); Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26); Employee noname = new Employee(4L, null, 50); AtomicReferenceArray<Employee> employees = new AtomicReferenceArray<>(new Employee[]{ yoda, luke, obiwan, noname }); assertThat(employees).filteredOn("age", 800) .containsOnly(yoda, obiwan);
// Name is bean class with 'first' and 'last' String properties // name is null for noname => it does not match the filter on "name.first" assertThat(employees).filteredOn("name.first", "Luke") .containsOnly(luke); assertThat(employees).filteredOn("name.last", "Vader") .isEmpty();
If you want to filter on null value, use
filteredOnNull(String)
as Java will resolve the call tofilteredOn(String, FilterOperator)
instead of this method.An
IntrospectionError
is thrown if the given propertyOrFieldName can't be found in one of the array elements.You can chain filters:
If you need more complex filter, use// fellowshipOfTheRing is an array of TolkienCharacter having race and name fields // 'not' filter is statically imported from Assertions.not assertThat(fellowshipOfTheRing).filteredOn("race.name", "Man") .filteredOn("name", not("Boromir")) .containsOnly(aragorn);
filteredOn(Condition)
and provide aCondition
to specify the filter to apply.- Parameters:
propertyOrFieldName
- the name of the property or field to readexpectedValue
- the value to compare element's property or field with- Returns:
- a new assertion object with the filtered array under test
- Throws:
IllegalArgumentException
- if the given propertyOrFieldName isnull
or empty.IntrospectionError
- if the given propertyOrFieldName can't be found in one of the array elements.- Since:
- 2.7.0 / 3.7.0
-
filteredOnNull
public AtomicReferenceArrayAssert<T> filteredOnNull(String propertyOrFieldName)
Filter the array under test keeping only elements whose property or field specified bypropertyOrFieldName
is null.exists it tries to read the value from a field. Reading private fields is supported by default, this can be globally disabled by calling
Assertions.setAllowExtractingPrivateFields(false)
.When reading nested property/field, if an intermediate value is null the whole nested property/field is considered to be null, thus reading "address.street.name" value will return null if "street" value is null.
As an example, let's check all employees 800 years old (yes, special employees):
Nested properties/fields are supported:Employee yoda = new Employee(1L, new Name("Yoda"), 800); Employee obiwan = new Employee(2L, new Name("Obiwan"), 800); Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26); Employee noname = new Employee(4L, null, 50); AtomicReferenceArray<Employee> employees = new AtomicReferenceArray<>(new Employee[]{ yoda, luke, obiwan, noname }); assertThat(employees).filteredOnNull("name") .containsOnly(noname);
An// Name is bean class with 'first' and 'last' String properties assertThat(employees).filteredOnNull("name.last") .containsOnly(yoda, obiwan, noname);
IntrospectionError
is thrown if the given propertyOrFieldName can't be found in one of the array elements.If you need more complex filter, use
filteredOn(Condition)
and provide aCondition
to specify the filter to apply.- Parameters:
propertyOrFieldName
- the name of the property or field to read- Returns:
- a new assertion object with the filtered array under test
- Throws:
IntrospectionError
- if the given propertyOrFieldName can't be found in one of the array elements.- Since:
- 2.7.0 / 3.7.0
-
filteredOn
public AtomicReferenceArrayAssert<T> filteredOn(String propertyOrFieldName, FilterOperator<?> filterOperator)
Filter the array under test keeping only elements having a property or field matching the filter expressed with theFilterOperator
, the property/field is specified bypropertyOrFieldName
parameter.The existing filters are :
Whatever filter is applied, it first tries to get the value from a property (named
propertyOrFieldName
), if no such property exists it tries to read the value from a field. Reading private fields is supported by default, this can be globally disabled by callingAssertions.setAllowExtractingPrivateFields(false)
.When reading nested property/field, if an intermediate value is null the whole nested property/field is considered to be null, thus reading "address.street.name" value will return null if "street" value is null.
As an example, let's check stuff on some special employees :
AnEmployee yoda = new Employee(1L, new Name("Yoda"), 800); Employee obiwan = new Employee(2L, new Name("Obiwan"), 800); Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26); AtomicReferenceArray<Employee> employees = new AtomicReferenceArray<>(new Employee[]{ yoda, luke, obiwan, noname }); // 'not' filter is statically imported from Assertions.not assertThat(employees).filteredOn("age", not(800)) .containsOnly(luke); // 'in' filter is statically imported from Assertions.in // Name is bean class with 'first' and 'last' String properties assertThat(employees).filteredOn("name.first", in("Yoda", "Luke")) .containsOnly(yoda, luke); // 'notIn' filter is statically imported from Assertions.notIn assertThat(employees).filteredOn("name.first", notIn("Yoda", "Luke")) .containsOnly(obiwan);
IntrospectionError
is thrown if the given propertyOrFieldName can't be found in one of the array elements.Note that combining filter operators is not supported, thus the following code is not correct:
// Combining filter operators like not(in(800)) is NOT supported // -> throws UnsupportedOperationException assertThat(employees).filteredOn("age", not(in(800))) .contains(luke);
You can chain filters:
If you need more complex filter, use// fellowshipOfTheRing is an array of TolkienCharacter having race and name fields // 'not' filter is statically imported from Assertions.not assertThat(fellowshipOfTheRing).filteredOn("race.name", "Man") .filteredOn("name", not("Boromir")) .containsOnly(aragorn);
filteredOn(Condition)
orfilteredOn(Predicate)
and provide aCondition
orPredicate
to specify the filter to apply.- Parameters:
propertyOrFieldName
- the name of the property or field to readfilterOperator
- the filter operator to apply- Returns:
- a new assertion object with the filtered array under test
- Throws:
IllegalArgumentException
- if the given propertyOrFieldName isnull
or empty.- Since:
- 2.7.0 / 3.7.0
-
filteredOn
public AtomicReferenceArrayAssert<T> filteredOn(Condition<? super T> condition)
Filter the array under test keeping only elements matching the givenCondition
.Let's check old employees whose age > 100:
You can combineEmployee yoda = new Employee(1L, new Name("Yoda"), 800); Employee obiwan = new Employee(2L, new Name("Obiwan"), 800); Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26); Employee noname = new Employee(4L, null, 50); AtomicReferenceArray<Employee> employees = new AtomicReferenceArray<>(new Employee[]{ yoda, luke, obiwan, noname }); // old employee condition, "old employees" describes the condition in error message // you just have to implement 'matches' method Condition<Employee> oldEmployees = new Condition<Employee>("old employees") { @Override public boolean matches(Employee employee) { return employee.getAge() > 100; } }; } assertThat(employees).filteredOn(oldEmployees) .containsOnly(yoda, obiwan);
Condition
with condition operator likeNot
:// 'not' filter is statically imported from Assertions.not assertThat(employees).filteredOn(not(oldEmployees)) .contains(luke, noname);
- Parameters:
condition
- the filter condition / predicate- Returns:
- a new assertion object with the filtered array under test
- Throws:
IllegalArgumentException
- if the given condition isnull
.- Since:
- 2.7.0 / 3.7.0
-
filteredOn
public AtomicReferenceArrayAssert<T> filteredOn(Predicate<? super T> predicate)
Filter the array under test into a list composed of the elements matching the givenPredicate
, allowing to perform assertions on the filtered list.Example : check old employees whose age > 100:
Employee yoda = new Employee(1L, new Name("Yoda"), 800); Employee obiwan = new Employee(2L, new Name("Obiwan"), 800); Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26); AtomicReferenceArray<Employee> employees = new AtomicReferenceArray<>(new Employee[]{ yoda, luke, obiwan, noname }); assertThat(employees).filteredOn(employee -> employee.getAge() > 100) .containsOnly(yoda, obiwan);
- Parameters:
predicate
- the filter predicate- Returns:
- a new assertion object with the filtered array under test
- Throws:
IllegalArgumentException
- if the given predicate isnull
.- Since:
- 3.16.0
-
filteredOn
public <U> AtomicReferenceArrayAssert<T> filteredOn(Function<? super T,U> function, U expectedValue)
Filter the array under test into a list composed of the elements for which the result of thefunction
is equal toexpectedValue
.It allows to filter elements in more safe way than by using
filteredOn(String, Object)
as it doesn't utilize introspection.As an example, let's check all employees 800 years old (yes, special employees):
If you need more complex filter, useEmployee yoda = new Employee(1L, new Name("Yoda"), 800); Employee obiwan = new Employee(2L, new Name("Obiwan"), 800); Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26); Employee noname = new Employee(4L, null, 50); AtomicReferenceArray<Employee> employees = new AtomicReferenceArray<>(new Employee[]{ yoda, luke, obiwan, noname }); assertThat(employees).filteredOn(Employee::getAge, 800) .containsOnly(yoda, obiwan); assertThat(employees).filteredOn(e -> e.getName(), null) .containsOnly(noname);
filteredOn(Predicate)
orfilteredOn(Condition)
.- Type Parameters:
U
- result type of the filter function- Parameters:
function
- the filter functionexpectedValue
- the expected value of the filter function- Returns:
- a new assertion object with the filtered array under test
- Throws:
IllegalArgumentException
- if the given function isnull
.- Since:
- 3.17.0
-
allMatch
public AtomicReferenceArrayAssert<T> allMatch(Predicate<? super T> predicate)
Verifies that all elements match the givenPredicate
.Example :
Note that you can achieve the same result withAtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[] {"a", "b", "c"}); AtomicReferenceArray<String> abcc = new AtomicReferenceArray<>(new String[] {"a", "b", "cc"}); // assertion will pass assertThat(abc).allMatch(s -> s.length() == 1); // assertion will fail assertThat(abcc).allMatch(s -> s.length() == 1);
are(Condition)
orhave(Condition)
.- Specified by:
allMatch
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
predicate
- the givenPredicate
.- Returns:
this
object.- Throws:
NullPointerException
- if the given predicate isnull
.AssertionError
- if an element cannot be cast to T.AssertionError
- if one or more elements don't satisfy the given predicate.- Since:
- 3.7.0
-
allMatch
public AtomicReferenceArrayAssert<T> allMatch(Predicate<? super T> predicate, String predicateDescription)
Verifies that all the elements of actual's array match the givenPredicate
. The predicate description is used to get an informative error message.Example :
The message of the failed assertion would be:AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[] {"a", "b", "c"}); AtomicReferenceArray<String> abcc = new AtomicReferenceArray<>(new String[] {"a", "b", "cc"}); // assertion will pass assertThat(abc).allMatch(s -> s.length() == 1, "length of 1"); // assertion will fail assertThat(abcc).allMatch(s -> s.length() == 1, "length of 1");
Expecting all elements of: <["a", "b", "cc"]> to match 'length of 1' predicate but this element did not: <"cc">
- Specified by:
allMatch
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
predicate
- the givenPredicate
.predicateDescription
- a description of thePredicate
used in the error message- Returns:
this
object.- Throws:
NullPointerException
- if the given predicate isnull
.AssertionError
- if an element cannot be cast to T.AssertionError
- if one or more elements don't satisfy the given predicate.- Since:
- 3.7.0
-
allSatisfy
public AtomicReferenceArrayAssert<T> allSatisfy(Consumer<? super T> requirements)
Verifies that all the elements satisfy given requirements expressed as aConsumer
.This is useful to perform a group of assertions on elements.
Grouping assertions example:
// myIcelanderFriends is an AtomicReferenceArray<Person> assertThat(myIcelanderFriends).allSatisfy(person -> { assertThat(person.getCountry()).isEqualTo("Iceland"); assertThat(person.getPhoneCountryCode()).isEqualTo("+354"); });
- Specified by:
allSatisfy
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
requirements
- the givenConsumer
.- Returns:
this
object.- Throws:
NullPointerException
- if the givenConsumer
isnull
.AssertionError
- if one or more elements don't satisfy given requirements.- Since:
- 3.7.0
-
allSatisfy
public AtomicReferenceArrayAssert<T> allSatisfy(ThrowingConsumer<? super T> requirements)
Verifies that all the elements satisfy the given requirements expressed as aThrowingConsumer
.This is useful to perform a group of assertions on elements.
This is the same assertion as
allSatisfy(Consumer)
but the given consumer can throw checked exceptions.
More precisely,RuntimeException
andAssertionError
are rethrown as they are andThrowable
wrapped in aRuntimeException
.Example:
// read() throws IOException // note that the code would not compile if isNotEmpty, startsWithA or startsWithZ were declared as a Consumer<Reader> ThrowingConsumer<Reader> isNotEmpty = reader -> assertThat(reader.read()).isEqualTo(-1); ThrowingConsumer<Reader> startsWithA = reader -> assertThat(reader.read()).isEqualTo('A'); // ABC.txt contains: ABC // XYZ.txt contains: XYZ AtomicReferenceArray<FileReader> fileReaders = new AtomicReferenceArray<>(new FileReader[] {new FileReader("ABC.txt"), new FileReader("XYZ.txt")}); // assertion succeeds as none of the files are empty assertThat(fileReaders).allSatisfy(isNotEmpty); // assertion fails as XYZ.txt does not start with 'A': assertThat(fileReaders).allSatisfy(startsWithA);
If the actual iterable is empty, this assertion succeeds as there is nothing to check.
- Specified by:
allSatisfy
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
requirements
- the givenThrowingConsumer
.- Returns:
this
object.- Throws:
NullPointerException
- if givenThrowingConsumer
is nullRuntimeException
- rethrown as is by the givenThrowingConsumer
or wrapping anyThrowable
.AssertionError
- if one or more elements don't satisfy the given requirements.- Since:
- 3.21.0
-
internalAllSatisfy
private AtomicReferenceArrayAssert<T> internalAllSatisfy(Consumer<? super T> requirements)
-
anyMatch
public AtomicReferenceArrayAssert<T> anyMatch(Predicate<? super T> predicate)
Verifies whether any elements match the providedPredicate
.Example :
Note that you can achieve the same result withAtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[] {"a", "b", "c"}); AtomicReferenceArray<String> abcc = new AtomicReferenceArray<>(new String[] {"a", "b", "cc"}); // assertion will pass assertThat(abc).anyMatch(s -> s.length() == 2); // assertion will fail assertThat(abcc).anyMatch(s -> s.length() > 2);
areAtLeastOne(Condition)
orhaveAtLeastOne(Condition)
.- Specified by:
anyMatch
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
predicate
- the givenPredicate
.- Returns:
this
object.- Throws:
NullPointerException
- if the given predicate isnull
.AssertionError
- if no elements satisfy the given predicate.- Since:
- 3.9.0
-
anySatisfy
public AtomicReferenceArrayAssert<T> anySatisfy(Consumer<? super T> requirements)
Verifies that at least one element satisfies the given requirements expressed as aConsumer
.This is useful to check that a group of assertions is verified by (at least) one element.
If the
AtomicReferenceArray
to assert is empty, the assertion will fail.Grouping assertions example:
// myIcelanderFriends is an AtomicReferenceArray<Person> assertThat(myIcelanderFriends).anySatisfy(person -> { assertThat(person.getCountry()).isEqualTo("Iceland"); assertThat(person.getPhoneCountryCode()).isEqualTo("+354"); assertThat(person.getSurname()).endsWith("son"); }); // assertion fails for empty group, whatever the requirements are. assertThat(emptyArray).anySatisfy($ -> { assertThat(true).isTrue(); });
- Specified by:
anySatisfy
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
requirements
- the givenConsumer
.- Returns:
this
object.- Throws:
NullPointerException
- if the givenConsumer
isnull
.AssertionError
- if all elements don't satisfy given requirements.- Since:
- 3.7.0
-
anySatisfy
public AtomicReferenceArrayAssert<T> anySatisfy(ThrowingConsumer<? super T> requirements)
Verifies that at least one element satisfies the given requirements expressed as aThrowingConsumer
.This is useful to check that a group of assertions is verified by (at least) one element.
This is the same assertion as
anySatisfy(Consumer)
but the given consumer can throw checked exceptions.
More precisely,RuntimeException
andAssertionError
are rethrown as they are andThrowable
wrapped in aRuntimeException
.Example:
// read() throws IOException // note that the code would not compile if startsWithA, startsWithY or startsWithZ were declared as a Consumer<Reader> ThrowingConsumer<Reader> startsWithA = reader -> assertThat(reader.read()).isEqualTo('A'); ThrowingConsumer<Reader> startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z'); // ABC.txt contains: ABC // XYZ.txt contains: XYZ AtomicReferenceArray<FileReader> fileReaders = new AtomicReferenceArray<>(new FileReader[] {new FileReader("ABC.txt"), new FileReader("XYZ.txt")}); // assertion succeeds as ABC.txt starts with 'A' assertThat(fileReaders).anySatisfy(startsWithA); // assertion fails none of the files starts with 'Z': assertThat(fileReaders).anySatisfy(startsWithZ);
If the actual iterable is empty, this assertion succeeds as there is nothing to check.
- Specified by:
anySatisfy
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
requirements
- the givenThrowingConsumer
.- Returns:
this
object.- Throws:
NullPointerException
- if givenThrowingConsumer
is nullRuntimeException
- rethrown as is by the givenThrowingConsumer
or wrapping anyThrowable
.AssertionError
- no elements satisfy the given requirements.- Since:
- 3.21.0
-
internalAnySatisfy
private AtomicReferenceArrayAssert<T> internalAnySatisfy(Consumer<? super T> requirements)
-
noneSatisfy
public AtomicReferenceArrayAssert<T> noneSatisfy(Consumer<? super T> restrictions)
Verifies that no elements satisfy the given restrictions expressed as aConsumer
.Example:
Note that this assertion succeeds if the group (collection, array, ...) is empty whatever the restrictions are.// assume that all icelander in myIcelanderFriends are not from Brazil assertThat(myIcelanderFriends).noneSatisfy(person -> { assertThat(person.getCountry()).isEqualTo("Brazil"); });
- Specified by:
noneSatisfy
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
restrictions
- the given restrictions asConsumer
that no elements should met.- Returns:
this
object.
-
noneSatisfy
public AtomicReferenceArrayAssert<T> noneSatisfy(ThrowingConsumer<? super T> restrictions)
Verifies that no elements satisfy the given restrictions expressed as aConsumer
.This is useful to check that a group of assertions is verified by (at least) one element.
This is the same assertion as
anySatisfy(Consumer)
but the given consumer can throw checked exceptions.
More precisely,RuntimeException
andAssertionError
are rethrown as they are andThrowable
wrapped in aRuntimeException
.Example:
// read() throws IOException // note that the code would not compile if startsWithA, startsWithY or startsWithZ were declared as a Consumer<Reader> ThrowingConsumer<Reader> startsWithA = reader -> assertThat(reader.read()).isEqualTo('A'); ThrowingConsumer<Reader> startsWithZ = reader -> assertThat(reader.read()).isEqualTo('Z'); // ABC.txt contains: ABC // XYZ.txt contains: XYZ AtomicReferenceArray<FileReader> fileReaders = new AtomicReferenceArray<>(new FileReader[] {new FileReader("ABC.txt"), new FileReader("XYZ.txt")}); // assertion succeeds as none of the file starts 'Z' assertThat(fileReaders).noneSatisfy(startsWithZ); // assertion fails as ABC.txt starts with 'A': assertThat(fileReaders).noneSatisfy(startsWithA);
Note that this assertion succeeds if the group (collection, array, ...) is empty whatever the restrictions are.
- Specified by:
noneSatisfy
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
restrictions
- the givenThrowingConsumer
.- Returns:
this
object.- Throws:
NullPointerException
- if givenThrowingConsumer
is nullRuntimeException
- rethrown as is by the givenThrowingConsumer
or wrapping anyThrowable
.AssertionError
- if one or more elements satisfy the given requirements.- Since:
- 3.21.0
-
internalNoneSatisfy
private AtomicReferenceArrayAssert<T> internalNoneSatisfy(Consumer<? super T> restrictions)
-
satisfiesExactly
@SafeVarargs public final AtomicReferenceArrayAssert<T> satisfiesExactly(Consumer<? super T>... requirements)
Verifies that each element satisfies the requirements corresponding to its index, so the first element must satisfy the first requirements, the second element the second requirements etc...Each requirements are expressed as a
Consumer
, there must be as many requirements as there are iterable elements.Example:
AtomicReferenceArray<TolkienCharacter> characters = new AtomicReferenceArray<>(new TolkienCharacter[] {frodo, aragorn, legolas}); // assertions succeed assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"), character -> assertThat(character.isMortal()).isTrue(), character -> assertThat(character.getName()).isEqualTo("Legolas")); // you can specify more that one assertion per requirements assertThat(characters).satisfiesExactly(character -> { assertThat(character.getRace()).isEqualTo("Hobbit"); assertThat(character.getName()).isEqualTo("Frodo"); }, character -> { assertThat(character.isMortal()).isTrue(); assertThat(character.getName()).isEqualTo("Aragorn"); }, character -> { assertThat(character.getRace()).isEqualTo("Elf"); assertThat(character.getName()).isEqualTo("Legolas"); }); // assertion fails as aragorn does not meet the second requirements assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"), character -> assertThat(character.isMortal()).isFalse(), character -> assertThat(character.getName()).isEqualTo("Legolas"));
- Specified by:
satisfiesExactly
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
requirements
- the requirements to meet.- Returns:
this
to chain assertions.- Throws:
NullPointerException
- if given requirements are null.AssertionError
- if any element does not satisfy the requirements at the same indexAssertionError
- if there are not as many requirements as there are iterable elements.- Since:
- 3.19.0
-
satisfiesExactly
@SafeVarargs public final AtomicReferenceArrayAssert<T> satisfiesExactly(ThrowingConsumer<? super T>... requirements)
Verifies that each element satisfies the requirements corresponding to its index, so the first element must satisfy the first requirements, the second element the second requirements etc...Each requirements are expressed as a
ThrowingConsumer
, there must be as many requirements as there are iterable elements.This is the same assertion as
satisfiesExactly(Consumer...)
but the given consumers can throw checked exceptions.
More precisely,RuntimeException
andAssertionError
are rethrown as they are andThrowable
wrapped in aRuntimeException
.Example:
AtomicReferenceArray<TolkienCharacter> characters = new AtomicReferenceArray<>(new TolkienCharacter[] {frodo, aragorn, legolas}); // the code would compile even if TolkienCharacter.getRace(), isMortal() or getName() threw a checked exception // assertions succeed assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"), character -> assertThat(character.isMortal()).isTrue(), character -> assertThat(character.getName()).isEqualTo("Legolas")); // you can specify more that one assertion per requirements assertThat(characters).satisfiesExactly(character -> { assertThat(character.getRace()).isEqualTo("Hobbit"); assertThat(character.getName()).isEqualTo("Frodo"); }, character -> { assertThat(character.isMortal()).isTrue(); assertThat(character.getName()).isEqualTo("Aragorn"); }, character -> { assertThat(character.getRace()).isEqualTo("Elf"); assertThat(character.getName()).isEqualTo("Legolas"); }); // assertion fails as aragorn does not meet the second requirements assertThat(characters).satisfiesExactly(character -> assertThat(character.getRace()).isEqualTo("Hobbit"), character -> assertThat(character.isMortal()).isFalse(), character -> assertThat(character.getName()).isEqualTo("Legolas"));
- Specified by:
satisfiesExactly
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
requirements
- the requirements to meet.- Returns:
this
to chain assertions.- Throws:
NullPointerException
- if given requirements are null.RuntimeException
- rethrown as is by the givenThrowingConsumer
or wrapping anyThrowable
.AssertionError
- if any element does not satisfy the requirements at the same indexAssertionError
- if there are not as many requirements as there are iterable elements.- Since:
- 3.21.0
-
satisfiesExactlyForProxy
protected AtomicReferenceArrayAssert<T> satisfiesExactlyForProxy(Consumer<? super T>[] requirements)
-
satisfiesExactlyInAnyOrder
@SafeVarargs public final AtomicReferenceArrayAssert<T> satisfiesExactlyInAnyOrder(Consumer<? super T>... requirements)
Verifies that at least one combination of iterable elements exists that satisfies the consumers in order (there must be as many consumers as iterable elements and once a consumer is matched it cannot be reused to match other elements).This is a variation of
satisfiesExactly(Consumer...)
where order does not matter.Examples:
AtomicReferenceArray<String> starWarsCharacterNames = new AtomicReferenceArray<>(new String[] {"Luke", "Leia", "Yoda"}); // these assertions succeed: assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"), // matches "Yoda" name -> assertThat(name).contains("L"), // matches "Luke" and "Leia" name -> { assertThat(name).hasSize(4); assertThat(name).doesNotContain("a"); // matches "Luke" but not "Leia" }) .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Yo"), name -> assertThat(name).contains("Lu"), name -> assertThat(name).contains("Le")) .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Le"), name -> assertThat(name).contains("Yo"), name -> assertThat(name).contains("Lu")); // this assertion fails as 3 consumer/requirements are expected assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"), name -> assertThat(name).contains("L")); // this assertion fails as no element contains "Han" (first consumer/requirements can't be met) assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Han"), name -> assertThat(name).contains("L"), name -> assertThat(name).contains("Y")); // this assertion fails as "Yoda" element can't satisfy any consumers/requirements (even though all consumers/requirements are met) assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("L"), name -> assertThat(name).contains("L"), name -> assertThat(name).contains("L")); // this assertion fails as no combination of elements can satisfy the consumers in order // the problem is if the last consumer is matched by Leia then no other consumer can match Luke (and vice versa) assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"), name -> assertThat(name).contains("o"), name -> assertThat(name).contains("L"));
- Specified by:
satisfiesExactlyInAnyOrder
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
requirements
- the consumers that are expected to be satisfied by the elements of the givenIterable
.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given consumers array or any consumer isnull
.AssertionError
- if there is no permutation of elements that satisfies the individual consumers in orderAssertionError
- if there are not as many requirements as there are iterable elements.- Since:
- 3.19.0
-
satisfiesExactlyInAnyOrder
@SafeVarargs public final AtomicReferenceArrayAssert<T> satisfiesExactlyInAnyOrder(ThrowingConsumer<? super T>... requirements)
Verifies that at least one combination of iterable elements exists that satisfies theThrowingConsumer
s in order (there must be as many consumers as iterable elements and once a consumer is matched it cannot be reused to match other elements).This is a variation of
satisfiesExactly(ThrowingConsumer...)
where order does not matter.Examples:
AtomicReferenceArray<String> starWarsCharacterNames = new AtomicReferenceArray<>(new String[] {"Luke", "Leia", "Yoda"}); // these assertions succeed: assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"), // matches "Yoda" name -> assertThat(name).contains("L"), // matches "Luke" and "Leia" name -> { assertThat(name).hasSize(4); assertThat(name).doesNotContain("a"); // matches "Luke" but not "Leia" }) .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Yo"), name -> assertThat(name).contains("Lu"), name -> assertThat(name).contains("Le")) .satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Le"), name -> assertThat(name).contains("Yo"), name -> assertThat(name).contains("Lu")); // this assertion fails as 3 consumers/requirements are expected assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"), name -> assertThat(name).contains("L")); // this assertion fails as no element contains "Han" (first consumer/requirements can't be met) assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Han"), name -> assertThat(name).contains("L"), name -> assertThat(name).contains("Y")); // this assertion fails as "Yoda" element can't satisfy any consumers/requirements (even though all consumers/requirements are met) assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("L"), name -> assertThat(name).contains("L"), name -> assertThat(name).contains("L")); // this assertion fails as no combination of elements can satisfy the consumers in order // the problem is if the last consumer is matched by Leia then no other consumer can match Luke (and vice versa) assertThat(starWarsCharacterNames).satisfiesExactlyInAnyOrder(name -> assertThat(name).contains("Y"), name -> assertThat(name).contains("o"), name -> assertThat(name).contains("L"));
- Specified by:
satisfiesExactlyInAnyOrder
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
requirements
- the consumers that are expected to be satisfied by the elements of the givenIterable
.- Returns:
- this assertion object.
- Throws:
NullPointerException
- if the given consumers array or any consumer isnull
.RuntimeException
- rethrown as is by the givenThrowingConsumer
or wrapping anyThrowable
.AssertionError
- if there is no permutation of elements that satisfies the individual consumers in orderAssertionError
- if there are not as many requirements as there are iterable elements.- Since:
- 3.21.0
-
satisfiesExactlyInAnyOrderForProxy
protected AtomicReferenceArrayAssert<T> satisfiesExactlyInAnyOrderForProxy(Consumer<? super T>[] requirements)
-
containsAnyOf
@SafeVarargs public final AtomicReferenceArrayAssert<T> containsAnyOf(T... values)
Verifies that the actual AtomicReferenceArray contains at least one of the given values.Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"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:
containsAnyOf
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
values
- the values whose at least one which is expected to be in theAtomicReferenceArray
under test.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the array of values isnull
.IllegalArgumentException
- if the array of values is empty and theAtomicReferenceArray
under test is not empty.AssertionError
- if theAtomicReferenceArray
under test isnull
.AssertionError
- if theAtomicReferenceArray
under test does not contain any of the givenvalues
.- Since:
- 2.9.0 / 3.9.0
-
containsAnyOfForProxy
protected AtomicReferenceArrayAssert<T> containsAnyOfForProxy(T[] values)
-
containsAnyElementsOf
public AtomicReferenceArrayAssert<T> containsAnyElementsOf(Iterable<? extends T> iterable)
Verifies that the actual AtomicReferenceArray contains at least one of the givenIterable
elements.Example :
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[]{"a", "b", "c"}); // assertions will pass assertThat(abc).containsAnyElementsOf(Arrays.asList("b")) .containsAnyElementsOf(Arrays.asList("b", "c")) .containsAnyElementsOf(Arrays.asList("a", "b", "c")) .containsAnyElementsOf(Arrays.asList("a", "b", "c", "d")) .containsAnyElementsOf(Arrays.asList("e", "f", "g", "b")); // assertions will fail assertThat(abc).containsAnyElementsOf(Arrays.asList("d")); assertThat(abc).containsAnyElementsOf(Arrays.asList("d", "e", "f", "g"));
- Specified by:
containsAnyElementsOf
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
iterable
- the iterable whose at least one element is expected to be in theAtomicReferenceArray
under test.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the iterable of expected values isnull
.IllegalArgumentException
- if the iterable of expected values is empty and theAtomicReferenceArray
under test is not empty.AssertionError
- if theAtomicReferenceArray
under test isnull
.AssertionError
- if theAtomicReferenceArray
under test does not contain any of elements from the givenIterable
.- Since:
- 2.9.0 / 3.9.0
-
noneMatch
public AtomicReferenceArrayAssert<T> noneMatch(Predicate<? super T> predicate)
Verifies that no elements match the givenPredicate
.Example :
Note that you can achieve the same result withAtomicReferenceArray<String> abcc = new AtomicReferenceArray<>(new String[]{"a", "b", "cc"}); // assertion will pass assertThat(abcc).noneMatch(s -> s.isEmpty()); // assertion will fail assertThat(abcc).noneMatch(s -> s.length() == 2);
areNot(Condition)
ordoNotHave(Condition)
.- Specified by:
noneMatch
in interfaceObjectEnumerableAssert<AtomicReferenceArrayAssert<T>,T>
- Parameters:
predicate
- the givenPredicate
.- Returns:
this
object.- Throws:
NullPointerException
- if the given predicate isnull
.AssertionError
- if an element cannot be cast to T.AssertionError
- if any element satisfy the given predicate.- Since:
- 3.9.0
-
getComparatorsByType
protected org.assertj.core.internal.TypeComparators getComparatorsByType()
-
getComparatorsForElementPropertyOrFieldTypes
protected org.assertj.core.internal.TypeComparators getComparatorsForElementPropertyOrFieldTypes()
-
internalFilteredOn
private AtomicReferenceArrayAssert<T> internalFilteredOn(String propertyOrFieldName, Object expectedValue)
-
internalFilteredOn
private AtomicReferenceArrayAssert<T> internalFilteredOn(Predicate<? super T> predicate)
-
-