IsSortedIterable 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 was ").appendValueList("[", ", ", "]", reversed ? IterableUtils.sortedReversedListCopy(iterable) : sortedListCopy(iterable)); } IsSortedIterable(final boolean reversed); static Matcher<Iterable<K>> sorted(); static Matcher<Iterable<K>> sortedReversed(); @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 was [<1>, <10>, <100>]", isSortedIterableMatcher, unsortedIterable); assertHasMismatchDescription("iterable was [<100>, <1>, <10>], while expected ordering was [<100>, <10>, <1>]", isReversedSortedIterableMatcher, unsortedIterable); }