IsDate extends TypeSafeMatcher<Date> { @Override protected void describeMismatchSafely(final Date date, final Description mismatchDescription) { mismatchDescription.appendValue(date).appendText(" has not"); expectedMatching(mismatchDescription); } IsDate(final Integer year, final Integer month, final Integer day); static Matcher<Date> hasYear(final int year); static Matcher<Date> hasMonth(final int month); static Matcher<Date> hasDay(final int day); static Matcher<Date> hasYearAndMonth(final int year, final int month); static Matcher<Date> hasYearMonthAndDay(final int year, final int month, final int day); @Override void describeTo(final Description description);  }
@Test public void testDescribeMismatchSafely() throws Exception { BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not year <%d>", date, dateWrongYear), IsDate.hasYear(dateWrongYear), date); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not id <%d>", date, dateWrongMonth), IsDate.hasMonth(dateWrongMonth), date); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not day <%d>", date, dateWrongDay), IsDate.hasDay(dateWrongDay), date); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not year <%d>, id <%d>", date, dateWrongYear, dateWrongMonth), IsDate.hasYearAndMonth(dateWrongYear, dateWrongMonth), date); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not year <%d>, id <%d>, day <%d>", date, dateWrongYear, dateWrongMonth, dateWrongDay), IsDate.hasYearMonthAndDay(dateWrongYear, dateWrongMonth, dateWrongDay), date); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not year <%d>, day <%d>", date, dateWrongYear, dateWrongDay), new IsDate(dateWrongYear, null, dateWrongDay), date); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not id <%d>, day <%d>", date, dateWrongMonth, dateWrongDay), new IsDate(null, dateWrongMonth, dateWrongDay), date); }