I'm using AssertJ for my tests and I noticed there's a method for checking if a List<T>
is sorted:
public static <T> void sorted(final List<T> actual) {
try {
assertThat(actual).isSorted();
} catch (AssertionError e) {
LOGGER.error(e.getMessage(), e);
throw e;
}
}
Is there a way to check if the list is sorted in descending order?
I know guava provides Ordering.natural().reverse().isOrdered(values)
but I want to take advantage of AssertJ's assert messages as it really helps a lot in debugging e.g.
group is not sorted because element 5:
<"4000366190001391">
is not less or equal than element 6:
<"4000206280001394">
group was:
<["4000206280001363",
"4000206280001364",
"4000206280001365",
"4000206280001373",
"4000206280001388",
"4000366190001391",
"4000206280001394",
"4000366190001401",
"4000206280001403",
"4000206280001405",
....]>