DateExt { public boolean isSameDay(Date anotherDate) { Calendar day = Calendar.getInstance(); day.setTime(date); day.set(Calendar.HOUR_OF_DAY, 0); day.set(Calendar.MINUTE, 0); day.set(Calendar.SECOND, 0); day.set(Calendar.MILLISECOND, 0); Calendar anotherDay = Calendar.getInstance(); anotherDay.setTime(anotherDate); anotherDay.set(Calendar.HOUR_OF_DAY, 0); anotherDay.set(Calendar.MINUTE, 0); anotherDay.set(Calendar.SECOND, 0); anotherDay.set(Calendar.MILLISECOND, 0); return day.equals(anotherDay); } DateExt(Date date); boolean isSameDay(Date anotherDate); boolean isDayBefore(Date anotherDate); Date getDateWithoutTime();  }
@Test public void isSameDay_shouldReturnTrueWhenOnlyTimeDifferent() { Calendar currentDate = Calendar.getInstance(); currentDate.set(2012, Calendar.MARCH, 01, 10, 00); Calendar pastDate = Calendar.getInstance(); pastDate.set(2012, Calendar.MARCH, 01, 12, 12); assertThat(new DateExt(pastDate.getTime()).isSameDay(currentDate.getTime()), is(true)); }
@Test public void isSameDay_shouldReturnFalseWhenDayDifferent() { Calendar currentDate = Calendar.getInstance(); currentDate.set(2012, Calendar.MARCH, 02, 10, 00); Calendar pastDate = Calendar.getInstance(); pastDate.set(2012, Calendar.MARCH, 01, 10, 10); assertThat(new DateExt(pastDate.getTime()).isSameDay(currentDate.getTime()), is(false)); }