CalendarUtil { public Date getDateAtOneAmNext(DAY_OF_WEEK day) { Calendar date = Calendar.getInstance(); date.set(Calendar.DAY_OF_WEEK, day.day); date.set(Calendar.HOUR, 1); date.set(Calendar.AM_PM, Calendar.AM); date.set(Calendar.MINUTE, 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); Calendar now = Calendar.getInstance(); while (date.before(now)) { date.add(Calendar.WEEK_OF_YEAR, 1); } return date.getTime(); }  Date getDateAtOneAmNext(DAY_OF_WEEK day); static final long ONE_WEEK_MILLIS; }
@Test public void testGetDateAtOneAmNext() throws Exception { Date nextReportDate = calendarUtil.getDateAtOneAmNext(FRI); Assert.assertNotNull(nextReportDate); Date now = new Date(); Assert.assertTrue("Next report date should be after the current date", nextReportDate.after(now)); Assert.assertTrue("The next scheduled date should be within a week", (nextReportDate.getTime() - now.getTime()) <= CalendarUtil.ONE_WEEK_MILLIS); }