IsDateInWeekOfYear extends TypeSafeMatcher<Date> { @Override protected void describeMismatchSafely(final Date date, final Description mismatchDescription) { mismatchDescription.appendValue(date).appendText(" is not in week of the year ").appendValue(weekOfYear); } IsDateInWeekOfYear(final int weekOfYear); static Matcher<Date> inWeekOfYear(final int week); @Override void describeTo(final Description description);  }
@Test public void testDescribeMismatchSafely() throws Exception { assertHasMismatchDescription(format("<%s> is not in week of the year <%d>", januaryDateInWeek53, 1), isWeek1Matcher, januaryDateInWeek53); assertHasMismatchDescription(format("<%s> is not in week of the year <%d>", decemberDateInWeek52, 1), isWeek1Matcher, decemberDateInWeek52); assertHasMismatchDescription(format("<%s> is not in week of the year <%d>", decemberDateInWeek53, 1), isWeek1Matcher, decemberDateInWeek53); assertHasMismatchDescription(format("<%s> is not in week of the year <%d>", januaryDateInWeek1, 52), isWeek52Matcher, januaryDateInWeek1); assertHasMismatchDescription(format("<%s> is not in week of the year <%d>", decemberDateInWeek1, 52), isWeek52Matcher, decemberDateInWeek1); assertHasMismatchDescription(format("<%s> is not in week of the year <%d>", decemberDateInWeek53, 52), isWeek52Matcher, decemberDateInWeek53); assertHasMismatchDescription(format("<%s> is not in week of the year <%d>", januaryDateInWeek1, 53), isWeek53Matcher, januaryDateInWeek1); assertHasMismatchDescription(format("<%s> is not in week of the year <%d>", decemberDateInWeek1, 53), isWeek53Matcher, decemberDateInWeek1); assertHasMismatchDescription(format("<%s> is not in week of the year <%d>", decemberDateInWeek52, 53), isWeek53Matcher, decemberDateInWeek52); }