Given
List<Integer> list = ...
I would like to test with AssertJ whether it is sorted. Something like:
assertThat(list).isSorted()
Is it possible?
Given
List<Integer> list = ...
I would like to test with AssertJ whether it is sorted. Something like:
assertThat(list).isSorted()
Is it possible?
AssertJ offers out of the box isSorted()
and isSortedAccordingTo(Comparator)
for list assertions:
List<String> strings = List.of("abc", "DEF");
assertThat(strings).isSorted(); // fails as "abc" is after "DEF" lexicographically
assertThat(strings).isSortedAccordingTo(String.CASE_INSENSITIVE_ORDER); // succeeds
import com.google.common.collect.Ordering;
And
assertTrue(Ordering.natural().isOrdered(list));