IsSortedIterableWithComparator extends TypeSafeMatcher<Iterable<K>> { @Override public void describeMismatchSafely(final Iterable<K> iterable, final Description mismatchDescription) { mismatchDescription.appendText("iterable was ").appendValueList("[", ", ", "]", listCopy(iterable)) .appendText(", while expected ordering ").appendValueList("[", ", ", "]", reversed ? sortedReversedListCopy(iterable, comparator) : sortedListCopy(iterable, comparator)); } IsSortedIterableWithComparator(final Comparator<K> comparator, final boolean reversed); static Matcher<Iterable<K>> sorted(final Comparator<K> comparator); static Matcher<Iterable<K>> sortedReversed(final Comparator<K> comparator); @Override boolean matchesSafely(final Iterable<K> actual); @Override void describeMismatchSafely(final Iterable<K> iterable, final Description mismatchDescription); @Override void describeTo(final Description description);  }
@Test public void testDescribeMismatchSafely() throws Exception { assertHasMismatchDescription("iterable was [<100>, <1>, <10>], while expected ordering [<100>, <10>, <1>]", isSortedIterableMatcher, unsortedIterable); assertHasMismatchDescription("iterable was [<100>, <1>, <10>], while expected ordering [<1>, <10>, <100>]", isReversedSortedIterableMatcher, unsortedIterable); }