IsMultimapKeyWithCollectionSize extends TypeSafeMatcher<Multimap<K, ?>> { @Override public void describeMismatchSafely(final Multimap<K, ?> multimap, final Description mismatchDescription) { if (multimap.containsKey(comparison)) { mismatchDescription.appendText("Multimap had element ").appendValue(comparison) .appendText(" with collection size ").appendValue(multimap.get(comparison).size()); } else { mismatchDescription.appendText("Multimap was not containing element ").appendValue(comparison); } } IsMultimapKeyWithCollectionSize(final K comparison, final int size); static Matcher<Multimap<K, ?>> keyWithSize(final K element, 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 { assumeThat(multimap.keySet(), hasSize(0)); multimap.put(comparison, ""); BaseMatcherTest.assertHasMismatchDescription(String.format("Multimap was not containing element \"%s\"", missingComparison), isMultimapMissingElementWithCollectionSizeMatcher, multimap); BaseMatcherTest.assertHasMismatchDescription(String.format( "Multimap had element \"%s\" with collection size <1>", comparison), isMultimapElementWithCollectionSizeMatcher, multimap); }