@Test
 public void testNextExecutionEverySecond() throws Exception {
   DateTime now = truncateToSeconds(DateTime.now());
   DateTime expected = truncateToSeconds(now.plusSeconds(1));
   ExecutionTime executionTime = ExecutionTime.forCron(quartzCronParser.parse(EVERY_SECOND));
   assertEquals(expected, executionTime.nextExecution(now));
 }
 /** Issue #24: next execution not properly calculated */
 @Test
 public void testTimeShiftingProperlyDone() throws Exception {
   ExecutionTime executionTime = ExecutionTime.forCron(quartzCronParser.parse("0 0/10 22 * * *"));
   DateTime nextExecution =
       executionTime.nextExecution(DateTime.now().withHourOfDay(15).withMinuteOfHour(27));
   assertEquals(22, nextExecution.getHourOfDay());
   assertEquals(0, nextExecution.getMinuteOfHour());
 }
 /** 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 #19 https://github.com/jmrozanec/cron-utils/issues/19 Reported case: When
   * nextExecution shifts to 32nd day (e.g. 2015-01-31 23:59:59 + 00:00:01), JodaTime will throw an
   * exception Expected: should shift one month
   */
  @Test
  public void testShiftTo32ndDay() {
    String expression = "0/1 * * 1/1 * ? *"; // every second every day
    ExecutionTime executionTime = ExecutionTime.forCron(quartzCronParser.parse(expression));

    DateTime now = new DateTime(2015, 1, 31, 23, 59, 59, 0);
    DateTime expected = now.plusSeconds(1);
    DateTime nextExecution = executionTime.nextExecution(now);

    assertEquals(expected, nextExecution);
  }
 /**
  * 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());
 }