IsDateWithTime extends TypeSafeMatcher<Date> { @Override protected void describeMismatchSafely(final Date date, final Description mismatchDescription) { mismatchDescription.appendValue(date).appendText(" has not"); expectedMatching(mismatchDescription); } IsDateWithTime(final Integer hour, final Integer min, final Integer sec, final Integer millis);  IsDateWithTime(final Integer hour, final ClockPeriod clockPeriod, final Integer min, final Integer sec,
                          final Integer millis); static Matcher<Date> hasHour(final int hour); static Matcher<Date> hasHour(final int hour, final ClockPeriod clockPeriod); static Matcher<Date> hasMinute(final int minute); static Matcher<Date> hasSecond(final int second); static Matcher<Date> hasMillisecond(final int millisecond); static Matcher<Date> hasHourAndMin(final int hour, final int minute); static Matcher<Date> hasHourAndMin(final int hour, final ClockPeriod clockPeriod, final int minute); static Matcher<Date> hasHourMinAndSec(final int hour, final int minute, final int second); static Matcher<Date> hasHourMinAndSec(final int hour, final ClockPeriod clockPeriod, final int minute,
                                                 final int second); static Matcher<Date> hasHourMinSecAndMillis(final int hour, final int minute, final int second,
                                                       final int millisecond); static Matcher<Date> hasHourMinSecAndMillis(final int hour, final ClockPeriod clockPeriod, final int minute,
                                                       final int second, final int millisecond); @Override void describeTo(final Description description);  }
@Test public void testDescribeMismatchSafely() throws Exception { BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not hour <%d>", eveningDate, morningDateHour), IsDateWithTime.hasHour(morningDateHour), eveningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not hour <%d AM>", eveningDate, morningDateHour), IsDateWithTime.hasHour(morningDateHour, AM), eveningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not hour <%d PM>", morningDate, eveningDateHour - LENGTH_12_HOUR_CLOCK), IsDateWithTime.hasHour(eveningDateHour - LENGTH_12_HOUR_CLOCK, PM), morningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not minute <%d>", eveningDate, morningDateMinute), IsDateWithTime.hasMinute(morningDateMinute), eveningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not second <%d>", eveningDate, morningDateSecond), IsDateWithTime.hasSecond(morningDateSecond), eveningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not millisecond <%d>", eveningDate, morningDateMillisecond), IsDateWithTime.hasMillisecond(morningDateMillisecond), eveningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not hour <%d>, minute <%d>", eveningDate, morningDateHour, morningDateMinute), IsDateWithTime.hasHourAndMin(morningDateHour, morningDateMinute), eveningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not hour <%d AM>, minute <%d>", eveningDate, morningDateHour, morningDateMinute), IsDateWithTime.hasHourAndMin(morningDateHour, AM, morningDateMinute), eveningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not hour <%d PM>, minute <%d>", morningDate, eveningDateHour - LENGTH_12_HOUR_CLOCK, eveningDateMinute), IsDateWithTime.hasHourAndMin(eveningDateHour - LENGTH_12_HOUR_CLOCK, PM, eveningDateMinute), morningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not hour <%d>, minute <%d>, second <%d>", eveningDate, morningDateHour, morningDateMinute, morningDateSecond), IsDateWithTime.hasHourMinAndSec(morningDateHour, morningDateMinute, morningDateSecond), eveningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not hour <%d AM>, minute <%d>, second <%d>", eveningDate, morningDateHour, morningDateMinute, morningDateSecond), IsDateWithTime.hasHourMinAndSec(morningDateHour, AM, morningDateMinute, morningDateSecond), eveningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not hour <%d PM>, minute <%d>, second <%d>", morningDate, eveningDateHour - LENGTH_12_HOUR_CLOCK, eveningDateMinute, eveningDateSecond), IsDateWithTime.hasHourMinAndSec(eveningDateHour - LENGTH_12_HOUR_CLOCK, PM, eveningDateMinute, eveningDateSecond), morningDate); BaseMatcherTest.assertHasMismatchDescription(format( "<%s> has not hour <%d>, minute <%d>, second <%d>, millisecond <%d>", eveningDate, morningDateHour, morningDateMinute, morningDateSecond, morningDateMillisecond), IsDateWithTime.hasHourMinSecAndMillis(morningDateHour, morningDateMinute, morningDateSecond, morningDateMillisecond), eveningDate); BaseMatcherTest.assertHasMismatchDescription(format( "<%s> has not hour <%d AM>, minute <%d>, second <%d>, millisecond <%d>", eveningDate, morningDateHour, morningDateMinute, morningDateSecond, morningDateMillisecond), IsDateWithTime.hasHourMinSecAndMillis(morningDateHour, AM, morningDateMinute, morningDateSecond, morningDateMillisecond), eveningDate); BaseMatcherTest.assertHasMismatchDescription(format( "<%s> has not hour <%d PM>, minute <%d>, second <%d>, millisecond <%d>", morningDate, eveningDateHour - LENGTH_12_HOUR_CLOCK, eveningDateMinute, eveningDateSecond, eveningDateMillisecond), IsDateWithTime.hasHourMinSecAndMillis(eveningDateHour - LENGTH_12_HOUR_CLOCK, PM, eveningDateMinute, eveningDateSecond, eveningDateMillisecond), morningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not minute <%d>, second <%d>, millisecond <%d>", eveningDate, morningDateMinute, morningDateSecond, morningDateMillisecond), new IsDateWithTime(null, morningDateMinute, morningDateSecond, morningDateMillisecond), eveningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not second <%d>, millisecond <%d>", eveningDate, morningDateSecond, morningDateMillisecond), new IsDateWithTime(null, null, morningDateSecond, morningDateMillisecond), eveningDate); BaseMatcherTest.assertHasMismatchDescription(format("<%s> has not minute <%d>, millisecond <%d>", eveningDate, morningDateMinute, morningDateMillisecond), new IsDateWithTime(null, morningDateMinute, null, morningDateMillisecond), eveningDate); }