/** Issue #30: execution time properly calculated */ @Test public void testSaturdayExecutionTime() { DateTime now = DateTime.now(); CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)); ExecutionTime executionTime = ExecutionTime.forCron(parser.parse("0 0 3 ? * 6")); DateTime last = executionTime.lastExecution(now); DateTime next = executionTime.nextExecution(now); assertNotEquals(last, next); }
/** * Test for issue #9 https://github.com/jmrozanec/cron-utils/issues/9 Reported case: If you write * a cron expression that contains a month or day of week, nextExection() ignores it. Expected: * should not ignore month or day of week field */ @Test public void testDoesNotIgnoreMonthOrDayOfWeek() { CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ); CronParser cronParser = new CronParser(cronDefinition); // seconds, minutes, hours, dayOfMonth, month, dayOfWeek ExecutionTime executionTime = ExecutionTime.forCron(cronParser.parse("0 11 11 11 11 ?")); DateTime now = new DateTime(2015, 4, 15, 0, 0, 0); DateTime whenToExecuteNext = executionTime.nextExecution(now); assertEquals(2015, whenToExecuteNext.getYear()); assertEquals(11, whenToExecuteNext.getMonthOfYear()); assertEquals(11, whenToExecuteNext.getDayOfMonth()); assertEquals(11, whenToExecuteNext.getHourOfDay()); assertEquals(11, whenToExecuteNext.getMinuteOfHour()); assertEquals(0, whenToExecuteNext.getSecondOfMinute()); }
@Before public void setUp() { quartzCronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)); }