IsSortedIterableWithComparator extends TypeSafeMatcher<Iterable<K>> { @Override public void describeTo(final Description description) { description.appendText("iterable sorted according to given comparator"); if (reversed) { description.appendText(" in reverse order"); } } 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 testDescribeTo() throws Exception { assertIsDescribedTo("iterable sorted according to given comparator", isSortedIterableMatcher); assertIsDescribedTo("iterable sorted according to given comparator in reverse order", isReversedSortedIterableMatcher); }