every0_15_30_Sec_At_9_30_PM.month("Nov-Feb");
every0_15_30_Sec_At_9_30_PM.second("0,15,30");
every0_15_30_Sec_At_9_30_PM.minute(30);
every0_15_30_Sec_At_9_30_PM.hour("21");
CalendarBasedTimeout calendarTimeout = new CalendarBasedTimeout(every0_15_30_Sec_At_9_30_PM);
Calendar firstTimeout = calendarTimeout.getFirstTimeout();
Assert.assertNotNull("first timeout is null", firstTimeout);
Date firstTimeoutDate = firstTimeout.getTime();
logger.debug("First timeout is " + firstTimeoutDate);
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 dayOfMonth = firstTimeout.get(Calendar.DAY_OF_MONTH);
int month = firstTimeout.get(Calendar.MONTH);
Assert.assertEquals("Unexpected second in first timeout " + firstTimeoutDate, 0, second);
Assert.assertEquals("Unexpected minute in first timeout " + firstTimeoutDate, 30, minute);
Assert.assertEquals("Unexpected hour in first timeout " + firstTimeoutDate, 21, hour);
Assert.assertEquals("Unexpected AM/PM in first timeout ", Calendar.PM, amOrPm);
Assert.assertEquals("Unexpected day of month in first timeout ", 31, dayOfMonth);
List<Integer> validMonths = new ArrayList<Integer>();
validMonths.add(Calendar.NOVEMBER);
validMonths.add(Calendar.DECEMBER);
validMonths.add(Calendar.JANUARY);
validMonths.add(Calendar.FEBRUARY);
Assert.assertTrue("Unexpected month: " + month, validMonths.contains(month));
Calendar nextTimeout = calendarTimeout.getNextTimeout(firstTimeout);
long diff = nextTimeout.getTimeInMillis() - firstTimeout.getTimeInMillis();
Assert.assertEquals("Unexpected next timeout " + nextTimeout.getTime(), 15 * 1000, diff);
Calendar currentSystemDate = new GregorianCalendar();
Calendar nextTimeoutFromNow = calendarTimeout.getNextTimeout(currentSystemDate);
logger.debug("Next timeout from now is " + nextTimeoutFromNow.getTime());
int nextMinute = nextTimeoutFromNow.get(Calendar.MINUTE);
int nextSecond = nextTimeoutFromNow.get(Calendar.SECOND);
int nextHour = nextTimeoutFromNow.get(Calendar.HOUR_OF_DAY);
int nextAmOrPM = nextTimeoutFromNow.get(Calendar.AM_PM);