Class AbstractLongArrayAssert<SELF extends AbstractLongArrayAssert<SELF>>
- All Implemented Interfaces:
ArraySortedAssert<AbstractArrayAssert<SELF,
,long[], Long>, Long> Assert<SELF,
,long[]> Descriptable<SELF>
,EnumerableAssert<AbstractEnumerableAssert<SELF,
,long[], Long>, Long> ExtensionPoints<SELF,
long[]>
- Direct Known Subclasses:
LongArrayAssert
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractLongArrayAssert
(long[] actual, Class<?> selfType) -
Method Summary
Modifier and TypeMethodDescriptioncontains
(long... values) Verifies that the actual array contains the given values, in any order.Verifies that the actual array contains the given value at the given index.Verifies that the actual array contains the values of the given array, in any order.containsAnyOf
(long... values) Verifies that the actual array contains at least one of the given values.containsAnyOf
(Long[] values) Verifies that the actual array contains at least one value of the given array.containsExactly
(long... values) Verifies that the actual group contains only the given values and nothing else, in order.containsExactly
(Long[] values) Verifies that the actual group contains only the values of the given array and nothing else, in order.containsExactlyInAnyOrder
(long... values) Verifies that the actual group contains exactly the given values and nothing else, in any order.containsExactlyInAnyOrder
(Long[] values) Verifies that the actual group contains exactly the values of the given array and nothing else, in any order.containsOnly
(long... values) Verifies that the actual array contains only the given values and nothing else, in any order.containsOnly
(Long[] values) Verifies that the actual array contains only the values of the given array and nothing else, in any order.containsOnlyOnce
(long... values) Verifies that the actual array contains the given values only once.containsOnlyOnce
(Long[] values) Verifies that the actual array contains the values of the given array only once.containsSequence
(long... sequence) Verifies that the actual array contains the given sequence, without any other values between them.containsSequence
(Long[] sequence) Verifies that the actual array contains the given sequence, without any other values between them.containsSubsequence
(long... subsequence) Verifies that the actual array contains the given subsequence (possibly with other values between them).containsSubsequence
(Long[] subsequence) Verifies that the actual array contains the given subsequence (possibly with other values between them).doesNotContain
(long... values) Verifies that the actual array does not contain the given values.doesNotContain
(long value, Index index) Verifies that the actual array does not contain the given value at the given index.doesNotContain
(Long[] values) Verifies that the actual array does not contain the values of the given array.Verifies that the actual array does not contain duplicates.endsWith
(long... sequence) Verifies that the actual array ends with the given sequence of values, without any other values between them.Verifies that the actual array ends with the given sequence of values, without any other values between them.hasSameSizeAs
(Iterable<?> other) Verifies that the actual group has the same size as givenIterable
.hasSize
(int expected) Verifies that the number of values in the actual group is equal to the given one.hasSizeBetween
(int lowerBoundary, int higherBoundary) Verifies that the number of values in the actual array is between the given boundaries (inclusive).hasSizeGreaterThan
(int boundary) Verifies that the number of values in the actual array is greater than the given boundary.hasSizeGreaterThanOrEqualTo
(int boundary) Verifies that the number of values in the actual array is greater than or equal to the given boundary.hasSizeLessThan
(int boundary) Verifies that the number of values in the actual array is less than the given boundary.hasSizeLessThanOrEqualTo
(int boundary) Verifies that the number of values in the actual array is less than or equal to the given boundary.void
isEmpty()
Verifies that the actual group of values is empty.Verifies that the actual group of values is not empty.void
Verifies that the actual group of values isnull
or empty.isSorted()
Verifies that the actual array is sorted in ascending order according to the natural ordering of its elements.isSortedAccordingTo
(Comparator<? super Long> 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.startsWith
(long... sequence) Verifies that the actual array starts with the given sequence of values, without any other values between them.startsWith
(Long[] sequence) Verifies that the actual array starts with the given sequence of values, without any other values between them.Revert to standard comparison for incoming assertion group element checks.usingElementComparator
(Comparator<? super Long> customComparator) Use given custom comparator instead of relying on actual type Aequals
method to compare group elements for incoming assertion checks.Methods inherited from class org.assertj.core.api.AbstractEnumerableAssert
hasSameSizeAs, inBinary, inHexadecimal
Methods inherited from class org.assertj.core.api.AbstractAssert
areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, 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, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, 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, as, as, describedAs, describedAs
-
Field Details
-
arrays
protected org.assertj.core.internal.LongArrays arrays
-
-
Constructor Details
-
AbstractLongArrayAssert
-
-
Method Details
-
isNullOrEmpty
public void isNullOrEmpty()Verifies that the actual group of values isnull
or empty.Example:
// assertions will pass List<String> strings = new ArrayList<>(); assertThat(strings).isNullOrEmpty(); assertThat(new int[] { }).isNullOrEmpty(); // assertions will fail assertThat(new String[] { "a", "b"}).isNullOrEmpty(); assertThat(Arrays.asList(1, 2, 3)).isNullOrEmpty();
-
isEmpty
public void isEmpty()Verifies that the actual group of values is empty.Example:
// assertions will pass assertThat(new ArrayList()).isEmpty(); assertThat(new int[] { }).isEmpty(); // assertions will fail assertThat(new String[] { "a", "b" }).isEmpty(); assertThat(Arrays.asList(1, 2, 3)).isEmpty();
-
isNotEmpty
Verifies that the actual group of values is not empty.Example:
// assertions will pass assertThat(new String[] { "a", "b" }).isNotEmpty(); assertThat(Arrays.asList(1, 2, 3)).isNotEmpty(); // assertions will fail assertThat(new ArrayList()).isNotEmpty(); assertThat(new int[] { }).isNotEmpty();
- Returns:
this
assertion object.
-
hasSize
Verifies that the number of values in the actual group is equal to the given one.Example:
// assertions will pass assertThat(new String[] { "a", "b" }).hasSize(2); assertThat(Arrays.asList(1, 2, 3)).hasSize(3); // assertions will fail assertThat(new ArrayList()).hasSize(1); assertThat(new int[] { 1, 2, 3 }).hasSize(2);
- Parameters:
expected
- the expected number of values in the actual group.- Returns:
this
assertion object.
-
hasSizeGreaterThan
Verifies that the number of values in the actual array is greater than the given boundary.Example:
// assertion will pass assertThat(new long[] { 1, 2, 3 }).hasSizeGreaterThan(2); // assertion will fail assertThat(new long[] { 1, 2, 3 }).hasSizeGreaterThan(6);
- 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
Verifies that the number of values in the actual array is greater than or equal to the given boundary.Example:
// assertions will pass assertThat(new long[] { 1, 2, 3 }).hasSizeGreaterThanOrEqualTo(2) .hasSizeGreaterThanOrEqualTo(3); // assertion will fail assertThat(new long[] { 1, 2, 3 }).hasSizeGreaterThanOrEqualTo(4);
- 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
Verifies that the number of values in the actual array is less than the given boundary.Example:
// assertion will pass assertThat(new long[] { 1, 2, 3 }).hasSizeLessThan(5); // assertion will fail assertThat(new long[] { 1, 2, 3 }).hasSizeLessThan(4);
- 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
Verifies that the number of values in the actual array is less than or equal to the given boundary.Example:
// assertions will pass assertThat(new long[] { 1, 2, 3 }).hasSizeLessThanOrEqualTo(5) .hasSizeLessThanOrEqualTo(3); // assertions will fail assertThat(new long[] { 1, 2, 3 }).hasSizeLessThanOrEqualTo(4);
- 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
Verifies that the number of values in the actual array is between the given boundaries (inclusive).Example:
// assertions will pass assertThat(new long[] { 1, 2, 3 }).hasSizeBetween(0, 4) .hasSizeBetween(3, 3); // assertions will fail assertThat(new long[] { 1, 2, 3 }).hasSizeBetween(4, 6); assertThat(new long[] { 1, 2, 3 }).hasSizeBetween(0, 2);
- 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
Verifies that the actual group has the same size as givenIterable
.Example:
Iterable<String> abc = newArrayList("a", "b", "c"); Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya); // assertion will pass assertThat(elvesRings).hasSameSizeAs(abc); // assertions will fail assertThat(elvesRings).hasSameSizeAs(Arrays.asList(1, 2)); assertThat(elvesRings).hasSameSizeAs(Arrays.asList(1, 2, 3, 4));
- Parameters:
other
- theIterable
to compare size with actual group.- Returns:
this
assertion object.
-
contains
Verifies that the actual array contains the given values, in any order.Example:
// assertions will pass assertThat(new long[] { 1L, 2L, 3L }).contains(1L, 2L); assertThat(new long[] { 1L, 2L, 3L }).contains(3L, 1L); assertThat(new long[] { 1L, 2L, 3L }).contains(1L, 3L, 2L); // assertions will fail assertThat(new long[] { 1L, 2L, 3L }).contains(1L, 4L); assertThat(new long[] { 1L, 2L, 3L }).contains(4L, 7L);
- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the given argument is an empty array and the actual array is not empty.AssertionError
- if the actual array isnull
.AssertionError
- if the actual array does not contain the given values.
-
contains
Verifies that the actual array contains the values of the given array, in any order.Example:
// assertions will pass assertThat(new long[] { 1L, 2L, 3L }).contains(new Long[] { 1L, 2L }); assertThat(new long[] { 1L, 2L, 3L }).contains(new Long[] { 3L, 1L }); assertThat(new long[] { 1L, 2L, 3L }).contains(new Long[] { 1L, 3L, 2L }); // assertions will fail assertThat(new long[] { 1L, 2L, 3L }).contains(new Long[] { 1L, 4L }); assertThat(new long[] { 1L, 2L, 3L }).contains(new Long[] { 4L, 7L });
- Parameters:
values
- the givenLong
array of values.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the given argument is an empty array and the actual array is not empty.AssertionError
- if the actual array isnull
.AssertionError
- if the actual array does not contain the given values.- Since:
- 3.19.0
-
containsOnly
Verifies that the actual array contains only the given values and nothing else, in any order.Example:
// assertions will pass assertThat(new long[] { 1L, 2L, 3L }).containsOnly(1L, 2L, 3L); assertThat(new long[] { 1L, 2L, 3L }).containsOnly(2L, 3L, 1L); assertThat(new long[] { 1L, 1L, 2L }).containsOnly(1L, 2L); // assertions will fail assertThat(new long[] { 1L, 2L, 3L }).containsOnly(1L, 2L, 3L, 4L); assertThat(new long[] { 1L, 2L, 3L }).containsOnly(4L, 7L);
- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the given argument is an empty array and the actual array is not empty.AssertionError
- if the actual array isnull
.AssertionError
- if the actual array does not contain the given values, i.e. the actual array contains some or none of the given values, or the actual array contains more values than the given ones.
-
containsOnly
Verifies that the actual array contains only the values of the given array and nothing else, in any order.Example:
// assertions will pass assertThat(new long[] { 1L, 2L, 3L }).containsOnly(new Long[] { 1L, 2L, 3L }); assertThat(new long[] { 1L, 2L, 3L }).containsOnly(new Long[] { 2L, 3L, 1L }); assertThat(new long[] { 1L, 1L, 2L }).containsOnly(new Long[] { 1L, 2L }); // assertions will fail assertThat(new long[] { 1L, 2L, 3L }).containsOnly(new Long[] { 1L, 2L, 3L, 4L }); assertThat(new long[] { 1L, 2L, 3L }).containsOnly(new Long[] { 4L, 7L });
- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the given argument is an empty array and the actual array is not empty.AssertionError
- if the actual array isnull
.AssertionError
- if the actual array does not contain the given values, i.e. the actual array contains some or none of the given values, or the actual array contains more values than the given ones.- Since:
- 3.19.0
-
containsOnlyOnce
Verifies that the actual array contains the given values only once.Examples :
// assertion will pass assertThat(new long[] { 1, 2, 3 }).containsOnlyOnce(1, 2); // assertions will fail assertThat(new long[] { 1, 2, 1 }).containsOnlyOnce(1); assertThat(new long[] { 1, 2, 3 }).containsOnlyOnce(4); assertThat(new long[] { 1, 2, 3, 3 }).containsOnlyOnce(0, 1, 2, 3, 4, 5);
- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the given argument is an empty array and the actual array is not empty.AssertionError
- if the actual array 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 than once these values.
-
containsOnlyOnce
Verifies that the actual array contains the values of the given array only once.Examples :
// assertion will pass assertThat(new long[] { 1, 2, 3 }).containsOnlyOnce(new Long[] { 1, 2 }); // assertions will fail assertThat(new long[] { 1, 2, 1 }).containsOnlyOnce(new Long[] { 1 }); assertThat(new long[] { 1, 2, 3 }).containsOnlyOnce(new Long[] { 4 }); assertThat(new long[] { 1, 2, 3, 3 }).containsOnlyOnce(new Long[] { 0, 1, 2, 3, 4, 5 });
- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the given argument is an empty array and the actual array is not empty.AssertionError
- if the actual array 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 than once these values.- Since:
- 3.19.0
-
containsSequence
Verifies that the actual array contains the given sequence, without any other values between them.Example:
// assertion will pass assertThat(new long[] { 1, 2, 3 }).containsSequence(1, 2); // assertion will fail assertThat(new long[] { 1, 2, 3 }).containsSequence(1, 3); assertThat(new long[] { 1, 2, 3 }).containsSequence(2, 1);
- Parameters:
sequence
- the sequence of values to look for.- Returns:
- myself assertion object.
- Throws:
AssertionError
- if the actual array isnull
.AssertionError
- if the given array isnull
.AssertionError
- if the given argument is an empty array and the actual array is not empty.AssertionError
- if the actual array does not contain the given sequence.
-
containsSequence
Verifies that the actual array contains the given sequence, without any other values between them.Example:
// assertion will pass assertThat(new long[] { 1, 2, 3 }).containsSequence(new Long[] { 1, 2 }); // assertion will fail assertThat(new long[] { 1, 2, 3 }).containsSequence(new Long[] { 1, 3 }); assertThat(new long[] { 1, 2, 3 }).containsSequence(new Long[] { 2, 1 });
- Parameters:
sequence
- the sequence of values to look for.- Returns:
- myself assertion object.
- Throws:
AssertionError
- if the actual array isnull
.AssertionError
- if the given array isnull
.AssertionError
- if the given argument is an empty array and the actual array is not empty.AssertionError
- if the actual array does not contain the given sequence.- Since:
- 3.19.0
-
containsSubsequence
Verifies that the actual array contains the given subsequence (possibly with other values between them).Example:
// assertion will pass assertThat(new long[] { 1, 2, 3 }).containsSubsequence(1, 2); assertThat(new long[] { 1, 2, 3 }).containsSubsequence(1, 3); // assertion will fail assertThat(new long[] { 1, 2, 3 }).containsSubsequence(2, 1);
- Parameters:
subsequence
- the subsequence of values to look for.- Returns:
- myself assertion object.
- Throws:
AssertionError
- if the actual array isnull
.AssertionError
- if the given array isnull
.AssertionError
- if the given argument is an empty array and the actual array is not empty.AssertionError
- if the actual array does not contain the given subsequence.
-
containsSubsequence
Verifies that the actual array contains the given subsequence (possibly with other values between them).Example:
// assertion will pass assertThat(new long[] { 1, 2, 3 }).containsSubsequence(new Long[] { 1, 2 }); assertThat(new long[] { 1, 2, 3 }).containsSubsequence(new Long[] { 1, 3 }); // assertion will fail assertThat(new long[] { 1, 2, 3 }).containsSubsequence(new Long[] { 2, 1 });
- Parameters:
subsequence
- the subsequence of values to look for.- Returns:
- myself assertion object.
- Throws:
AssertionError
- if the actual array isnull
.AssertionError
- if the given array isnull
.AssertionError
- if the given argument is an empty array and the actual array is not empty.AssertionError
- if the actual array does not contain the given subsequence.- Since:
- 3.19.0
-
contains
Verifies that the actual array contains the given value at the given index.Example:
// assertions will pass assertThat(new long[] { 1L, 2L, 3L }).contains(1L, atIndex(O)); assertThat(new long[] { 1L, 2L, 3L }).contains(3L, atIndex(2)); // assertions will fail assertThat(new long[] { 1L, 2L, 3L }).contains(1L, atIndex(1)); assertThat(new long[] { 1L, 2L, 3L }).contains(4L, atIndex(2));
- Parameters:
value
- the value to look for.index
- the index where the value should be stored in the actual array.- Returns:
- myself assertion object.
- Throws:
AssertionError
- if the actual array 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 array.AssertionError
- if the actual array does not contain the given value at the given index.
-
doesNotContain
Verifies that the actual array does not contain the given values.Example:
// assertion will pass assertThat(new long[] { 1L, 2L, 3L }).doesNotContain(4L); // assertion will fail assertThat(new long[] { 1L, 2L, 3L }).doesNotContain(2L);
- 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 array isnull
.AssertionError
- if the actual array contains any of the given values.
-
doesNotContain
Verifies that the actual array does not contain the values of the given array.Example:
// assertion will pass assertThat(new long[] { 1L, 2L, 3L }).doesNotContain(new Long[] { 4L }); // assertion will fail assertThat(new long[] { 1L, 2L, 3L }).doesNotContain(new Long[] { 2L });
- 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 array isnull
.AssertionError
- if the actual array contains any of the given values.- Since:
- 3.19.0
-
doesNotContain
Verifies that the actual array does not contain the given value at the given index.Example:
// assertions will pass assertThat(new long[] { 1L, 2L, 3L }).doesNotContain(1L, atIndex(1)); assertThat(new long[] { 1L, 2L, 3L }).doesNotContain(2L, atIndex(0)); // assertions will fail assertThat(new long[] { 1L, 2L, 3L }).doesNotContain(1L, atIndex(0)); assertThat(new long[] { 1L, 2L, 3L }).doesNotContain(2L, atIndex(1));
- Parameters:
value
- the value to look for.index
- the index where the value should be stored in the actual array.- Returns:
- myself assertion object.
- Throws:
AssertionError
- if the actual array isnull
.NullPointerException
- if the givenIndex
isnull
.AssertionError
- if the actual array contains the given value at the given index.
-
doesNotHaveDuplicates
Verifies that the actual array does not contain duplicates.Example:
// assertion will pass assertThat(new long[] { 1L, 2L, 3L }).doesNotHaveDuplicates(); // assertion will fail assertThat(new long[] { 1L, 1L, 2L, 3L }).doesNotHaveDuplicates();
- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual array isnull
.AssertionError
- if the actual array contains duplicates.
-
startsWith
Verifies that the actual array starts with the given sequence of values, without any other values between them. Similar to
, but it also verifies that the first element in the sequence is also first element of the actual array.containsSequence(long...)
Example:
// assertion will pass assertThat(new long[] { 1L, 2L, 3L }).startsWith(1L, 2L); // assertion will fail assertThat(new long[] { 1L, 2L, 3L }).startsWith(2L, 3L);
- Parameters:
sequence
- the sequence of values to look for.- Returns:
- myself assertion object.
- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the given argument is an empty array and the actual array is not empty.AssertionError
- if the actual array isnull
.AssertionError
- if the actual array does not start with the given sequence.
-
startsWith
Verifies that the actual array starts with the given sequence of values, without any other values between them. Similar to
, but it also verifies that the first element in the sequence is also first element of the actual array.containsSequence(Long[])
Example:
// assertion will pass assertThat(new long[] { 1L, 2L, 3L }).startsWith(new Long[] { 1L, 2L }); // assertion will fail assertThat(new long[] { 1L, 2L, 3L }).startsWith(new Long[] { 2L, 3L });
- Parameters:
sequence
- the sequence of values to look for.- Returns:
- myself assertion object.
- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the given argument is an empty array and the actual array is not empty.AssertionError
- if the actual array isnull
.AssertionError
- if the actual array does not start with the given sequence.- Since:
- 3.19.0
-
endsWith
Verifies that the actual array ends with the given sequence of values, without any other values between them. Similar to
, but it also verifies that the last element in the sequence is also last element of the actual array.containsSequence(long...)
Example:
// assertion will pass assertThat(new long[] { 1L, 2L, 3L }).endsWith(2L, 3L); // assertion will fail assertThat(new long[] { 1L, 2L, 3L }).endsWith(3L, 4L);
- Parameters:
sequence
- the sequence of values to look for.- Returns:
- myself assertion object.
- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the actual array isnull
.AssertionError
- if the actual array does not end with the given sequence.
-
endsWith
Verifies that the actual array ends with the given sequence of values, without any other values between them. Similar to
, but it also verifies that the last element in the sequence is also last element of the actual array.containsSequence(Long[])
Example:
// assertion will pass assertThat(new long[] { 1L, 2L, 3L }).endsWith(new Long[] { 2L, 3L }); // assertion will fail assertThat(new long[] { 1L, 2L, 3L }).endsWith(new Long[] { 3L, 4L });
- Parameters:
sequence
- the sequence of values to look for.- Returns:
- myself assertion object.
- Throws:
NullPointerException
- if the given argument isnull
.AssertionError
- if the actual array isnull
.AssertionError
- if the actual array does not end with the given sequence.- Since:
- 3.19.0
-
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)
- Returns:
this
assertion object.
-
isSortedAccordingTo
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.- Parameters:
comparator
- theComparator
used to compare array elements- Returns:
this
assertion object.
-
usingElementComparator
Use given custom comparator instead of relying on actual type Aequals
method to compare group elements for incoming assertion checks.Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.
Examples :// compares invoices by payee assertThat(invoiceList).usingComparator(invoicePayeeComparator).isEqualTo(expectedInvoiceList); // compares invoices by date, doesNotHaveDuplicates and contains both use the given invoice date comparator assertThat(invoiceList).usingComparator(invoiceDateComparator).doesNotHaveDuplicates().contains(may2010Invoice); // as assertThat(invoiceList) creates a new assertion, it falls back to standard comparison strategy // based on Invoice's equal method to compare invoiceList elements to lowestInvoice. assertThat(invoiceList).contains(lowestInvoice); // standard comparison : the fellowshipOfTheRing includes Gandalf but not Sauron (believe me) ... assertThat(fellowshipOfTheRing).contains(gandalf) .doesNotContain(sauron); // ... but if we compare only races, Sauron is in fellowshipOfTheRing because he's a Maia like Gandalf. assertThat(fellowshipOfTheRing).usingElementComparator(raceComparator) .contains(sauron);
- Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.
-
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)
.- Returns:
this
assertion object.
-
containsExactly
Verifies that the actual group contains only the given values and nothing else, in order.Example :
long[] longs = { 1, 2, 3 }; // assertion will pass assertThat(longs).containsExactly(1, 2, 3); // assertion will fail as actual and expected order differ assertThat(longs).containsExactly(2, 1, 3);
- 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 given argument is an empty array and the actual array is not empty.AssertionError
- if the actual group does not contain the given values with same order, i.e. the actual group contains some or none of the given values, or the actual group contains more values than the given ones or values are the same but the order is not.
-
containsExactly
Verifies that the actual group contains only the values of the given array and nothing else, in order.Example :
long[] longs = { 1, 2, 3 }; // assertion will pass assertThat(longs).containsExactly(new Long[] { 1, 2, 3 }); // assertion will fail as actual and expected order differ assertThat(longs).containsExactly(new Long[] { 2, 1, 3 });
- 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 given argument is an empty array and the actual array is not empty.AssertionError
- if the actual group does not contain the given values with same order, i.e. the actual group contains some or none of the given values, or the actual group contains more values than the given ones or values are the same but the order is not.- Since:
- 3.19.0
-
containsExactlyInAnyOrder
Verifies that the actual group contains exactly the given values and nothing else, in any order.
Example :
// assertions will pass assertThat(new long[] { 1L, 2L }).containsExactlyInAnyOrder(1L, 2L); assertThat(new long[] { 1L, 2L, 1L }).containsExactlyInAnyOrder(1L, 1L, 2L); // assertions will fail assertThat(new long[] { 1L, 2L }).containsExactlyInAnyOrder(1L); assertThat(new long[] { 1L }).containsExactlyInAnyOrder(1L, 2L); assertThat(new long[] { 1L, 2L, 1L }).containsExactlyInAnyOrder(1L, 2L);
- 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 given argument is an empty array and the actual array is not empty.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.6.0 / 3.6.0
-
containsExactlyInAnyOrder
Verifies that the actual group contains exactly the values of the given array and nothing else, in any order.
Example :
// assertions will pass assertThat(new long[] { 1L, 2L }).containsExactlyInAnyOrder(new Long[] { 1L, 2L }); assertThat(new long[] { 1L, 2L, 1L }).containsExactlyInAnyOrder(new Long[] { 1L, 1L, 2L }); // assertions will fail assertThat(new long[] { 1L, 2L }).containsExactlyInAnyOrder(new Long[] { 1L }); assertThat(new long[] { 1L }).containsExactlyInAnyOrder(new Long[] { 1L, 2L }); assertThat(new long[] { 1L, 2L, 1L }).containsExactlyInAnyOrder(new Long[] { 1L, 2L });
- 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 given argument is an empty array and the actual array is not empty.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:
- 3.19.0
-
containsAnyOf
Verifies that the actual array contains at least one of the given values.Example :
long[] oneTwoThree = { 1L, 2L, 3L }; // assertions will pass assertThat(oneTwoThree).containsAnyOf(2L) .containsAnyOf(2L, 3L) .containsAnyOf(1L, 2L, 3L) .containsAnyOf(1L, 2L, 3L, 4L) .containsAnyOf(5L, 6L, 7L, 2L); // assertions will fail assertThat(oneTwoThree).containsAnyOf(4L); assertThat(oneTwoThree).containsAnyOf(4L, 5L, 6L, 7L);
- Parameters:
values
- the values whose at least one which is expected to be in the array under test.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the array of values isnull
.AssertionError
- if the array of values is empty and the array under test is not empty.AssertionError
- if the array under test isnull
.AssertionError
- if the array under test does not contain any of the givenvalues
.- Since:
- 2.9.0 / 3.9.0
-
containsAnyOf
Verifies that the actual array contains at least one value of the given array.Example :
long[] oneTwoThree = { 1L, 2L, 3L }; // assertions will pass assertThat(oneTwoThree).containsAnyOf(new Long[] { 2L }) .containsAnyOf(new Long[] { 2L, 3L }) .containsAnyOf(new Long[] { 1L, 2L, 3L }) .containsAnyOf(new Long[] { 1L, 2L, 3L, 4L }) .containsAnyOf(new Long[] { 5L, 6L, 7L, 2L }); // assertions will fail assertThat(oneTwoThree).containsAnyOf(new Long[] { 4L }); assertThat(oneTwoThree).containsAnyOf(new Long[] { 4L, 5L, 6L, 7L });
- Parameters:
values
- the array of values whose at least one which is expected to be in the array under test.- Returns:
this
assertion object.- Throws:
NullPointerException
- if the array of values isnull
.AssertionError
- if the array of values is empty and the array under test is not empty.AssertionError
- if the array under test isnull
.AssertionError
- if the array under test does not contain any of the givenvalues
.- Since:
- 3.19.0
-