IsMapWithSameKeySet extends TypeSafeMatcher<Map<? extends K, ?>> { @Override public void describeTo(final Description description) { description.appendText("map containing same key set as ").appendValueList("[", ", ", "]", comparisonMap.entrySet()); } IsMapWithSameKeySet(final Map<? extends K, ?> comparisonMap); static Matcher<Map<? extends K, ?>> hasSameKeySet(final Map<? extends K, ?> comparisonMap); @Override boolean matchesSafely(final Map<? extends K, ?> map); @Override void describeMismatchSafely(final Map<? extends K, ?> map, final Description mismatchDescription); @Override void describeTo(final Description description);  }
@Test public void testDescribeTo() throws Exception { assertIsDescribedTo("map containing same key set as [<1=1>, <2=2>, <3=3>, <4=4>]", isMapWithSameKeySetMatcher); }