Top Description Methods
org.assertj.core.api

public Interface ArraySortedAssert<SELF extends ArraySortedAssert<SELF, ELEMENT>, ELEMENT>

Known Direct Implementers
org.assertj.core.api.AtomicReferenceArrayAssert, org.assertj.core.api.AbstractArrayAssert, org.assertj.core.api.AbstractObjectArrayAssert
Type Parameters
<SELF>
the "self" type of this assertion class that must be a array type (e.g. arrays, collections).
Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
<ELEMENT>
the array element type.
Imports
java.util.Comparator

Assertions applicable to primitive arrays or arrays of elements either naturally Comparable or according to a given Comparator.

Note that the contract defined here is can't be totally applied to List (that's why its name is not SortedAssert), the differences being that we can't check that - for empty List - the list parameter is comparable or compatible with given comparator due to type erasure.

Authors
Joel Costigliola, Mikhail Mazursky

Method Summary

Modifier and TypeMethod and Description
public SELF

Returns:

this assertion object.
isSorted
()

Verifies that the actual array is sorted in ascending order according to the natural ordering of its elements.

public SELF

Returns:

this assertion object.
isSortedAccordingTo
(Comparator<? super ELEMENT>
the Comparator used to compare array elements
comparator
)

Verifies that the actual array is sorted according to the given comparator.

Method Detail

isSortedback to summary
public SELF 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)
Empty or one element arrays are considered sorted (unless the array element type is not Comparable).

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual array is not sorted in ascending order according to the natural ordering of its elements.
  • if the actual array is null.
  • if the actual array element type does not implement Comparable.
  • if the actual array elements are not mutually Comparable.
isSortedAccordingToback to summary
public SELF isSortedAccordingTo(Comparator<? super ELEMENT> 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.

Parameters
comparator:Comparator<? super ELEMENT>

the Comparator used to compare array elements

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual array is not sorted according to the given comparator.
  • if the actual array is null.
  • if the actual array elements are not mutually comparable according to given Comparator.
NullPointerException:
if the given comparator is null.