IsMultisetElementWithCount extends TypeSafeMatcher<Multiset<E>> { @Override public void describeMismatchSafely(final Multiset<E> multiset, final Description mismatchDescription) { if (multiset.contains(comparison)) { mismatchDescription.appendText("Multiset had element ").appendValue((Object) comparison) .appendText(" with count ").appendValue(multiset.count(comparison)); } else { mismatchDescription.appendText("Multiset was not containing element ").appendValue(comparison); } } IsMultisetElementWithCount(final E comparison, final int size); static Matcher<Multiset<E>> elementWithCount(final E element, final int size); @Override boolean matchesSafely(final Multiset<E> actual); @Override void describeMismatchSafely(final Multiset<E> multiset, final Description mismatchDescription); @Override void describeTo(final Description description);  }
@Test public void testDescribeMismatchSafely() throws Exception { assumeThat(multiset.size(), equalTo(0)); multiset.add(comparison); BaseMatcherTest.assertHasMismatchDescription(String.format("Multiset was not containing element \"%s\"", nonContainedComparison), isMissingMultisetElementWithCountMatcher, multiset); BaseMatcherTest.assertHasMismatchDescription(String.format("Multiset had element \"%s\" with count <1>", comparison), isMultisetElementWithCountMatcher, multiset); }