IsMultimapWithKeySetSize extends TypeSafeMatcher<Multimap<K, ?>> { @Override public void describeMismatchSafely(final Multimap<K, ?> multimap, final Description mismatchDescription) { mismatchDescription.appendText(" Multimap had key set with ").appendValue(multimap.keySet().size()).appendText( " elements"); } IsMultimapWithKeySetSize(final int size); static Matcher<Multimap<K, ?>> emptyKeySet(); static Matcher<Multimap<K, ?>> keySetWithSize(final int size); @Override boolean matchesSafely(final Multimap<K, ?> actual); @Override void describeMismatchSafely(final Multimap<K, ?> multimap, final Description mismatchDescription); @Override void describeTo(final Description description);  }
@Test public void testDescribeMismatchSafely() throws Exception { multimap.put("A", ""); multimap.put("B", ""); assumeThat(multimap.keySet(), hasSize(2)); BaseMatcherTest.assertHasMismatchDescription("Multimap had key set with <2> elements", isMultimapElementWithCollectionEmptyMatcher, multimap); BaseMatcherTest.assertHasMismatchDescription("Multimap had key set with <2> elements", isMultimapElementWithCollectionSizeMatcher, multimap); }