Package org.fest.assertions.core
Interface ArraySortedAssert<S,E>
-
- Type Parameters:
S
- 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.E
- the array element type.
- All Known Implementing Classes:
BooleanArrayAssert
,ByteArrayAssert
,CharArrayAssert
,DoubleArrayAssert
,FloatArrayAssert
,IntArrayAssert
,LongArrayAssert
,ObjectArrayAssert
,ShortArrayAssert
public interface ArraySortedAssert<S,E>
Assertions applicable to primitive arrays or arrays of elements either naturallyComparable
or according to a givenComparator
.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.
- Author:
- Joel Costigliola, Mikhail Mazursky
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description S
isSorted()
Verifies that the actual array is sorted into ascending order according to the natural ordering of its elements.S
isSortedAccordingTo(java.util.Comparator<? super E> comparator)
Verifies that the actual array is sorted according to the given comparator. Empty arrays are considered sorted whatever the comparator is. One element arrays are considered sorted if element is compatible with comparator, otherwise an AssertionError is thrown.
-
-
-
Method Detail
-
isSorted
S isSorted()
Verifies that the actual array is sorted into 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.- Throws:
java.lang.AssertionError
- if the actual array is not sorted into ascending order according to the natural ordering of its elements.java.lang.AssertionError
- if the actual array isnull
.java.lang.AssertionError
- if the actual array element type does not implementComparable
.java.lang.AssertionError
- if the actual array elements are not mutuallyComparable
.
-
isSortedAccordingTo
S isSortedAccordingTo(java.util.Comparator<? super E> comparator)
Verifies that the actual array is sorted according to the given comparator. Empty arrays are considered sorted whatever the comparator is. One element arrays are considered sorted if element is compatible with comparator, otherwise an AssertionError is thrown.- Parameters:
comparator
- theComparator
used to compare array elements- Returns:
this
assertion object.- Throws:
java.lang.AssertionError
- if the actual array is not sorted according to the given comparator.java.lang.AssertionError
- if the actual array isnull
.java.lang.NullPointerException
- if the given comparator isnull
.java.lang.AssertionError
- if the actual array elements are not mutually comparable according to given Comparator.
-
-