ScheduleExpression everyMonWedFriTwelveThirtyNoon = this.getTimezoneSpecificScheduleExpression();
everyMonWedFriTwelveThirtyNoon.hour(12);
everyMonWedFriTwelveThirtyNoon.second("30");
everyMonWedFriTwelveThirtyNoon.dayOfWeek("Mon,Wed,Fri");
CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(everyMonWedFriTwelveThirtyNoon);
Calendar firstTimeout = calendarTimeout.getFirstTimeout();
Assert.assertNotNull("first timeout is null", firstTimeout);
Date firstTimeoutDate = firstTimeout.getTime();
int minute = firstTimeout.get(Calendar.MINUTE);
int second = firstTimeout.get(Calendar.SECOND);
int hour = firstTimeout.get(Calendar.HOUR_OF_DAY);
int amOrPm = firstTimeout.get(Calendar.AM_PM);
int dayOfWeek = firstTimeout.get(Calendar.DAY_OF_WEEK);
Assert.assertEquals("Unexpected second in first timeout " + firstTimeoutDate, 30, second);
Assert.assertEquals("Unexpected minute in first timeout " + firstTimeoutDate, 0, minute);
Assert.assertEquals("Unexpected hour in first timeout " + firstTimeoutDate, 12, hour);
Assert.assertEquals("Unexpected AM/PM in first timeout ", Calendar.PM, amOrPm);
List<Integer> validDays = new ArrayList<Integer>();
validDays.add(Calendar.MONDAY);
validDays.add(Calendar.WEDNESDAY);
validDays.add(Calendar.FRIDAY);
Assert.assertTrue("Unexpected day of week: " + dayOfWeek + " in first timeout", validDays.contains(dayOfWeek));
Calendar previousTimeout = firstTimeout;
for (int i = 1; i <= 180; i++) {
Calendar nextTimeout = calendarTimeout.getNextTimeout(previousTimeout);
Assert.assertNotNull("Next timeout is null", nextTimeout);
Assert.assertNotNull("Next timeout is *before* the current time", nextTimeout.after(previousTimeout));
Date nextTimeoutDate = nextTimeout.getTime();