Skip to content

Commit

Permalink
Merge pull request #450 from IndeedSi/402-add-test-case
Browse files Browse the repository at this point in the history
#402: add a test case for the issue
  • Loading branch information
jmrozanec authored Oct 12, 2020
2 parents 8a373b0 + c2ced5d commit 2302af5
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/test/java/com/cronutils/Issue402Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.cronutils;

import com.cronutils.model.Cron;
import com.cronutils.model.CronType;
import com.cronutils.model.definition.CronDefinitionBuilder;
import com.cronutils.model.time.ExecutionTime;
import com.cronutils.parser.CronParser;
import org.junit.Ignore;
import org.junit.Test;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

@Ignore
public class Issue402Test {
@Test
public void test() {
CronParser parser = new CronParser( CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
final Cron cron = parser.parse("0 0 0 1 3 ? 2001/2");
// CronDescriptor cd = CronDescriptor.instance(Locale.US);
// System.out.println(cd.describe(cron));

ExecutionTime execution = ExecutionTime.forCron(cron);

LocalDate date = LocalDate.of(2015, 1, 15);
ZonedDateTime currentDateTime = ZonedDateTime.of(date, LocalTime.MIDNIGHT, ZoneOffset.UTC);

Optional<ZonedDateTime> nextExecution = execution.nextExecution(currentDateTime);
assertTrue(nextExecution.isPresent());
assertEquals(ZonedDateTime.of(LocalDate.of(2015, 3, 1), LocalTime.MIDNIGHT, ZoneOffset.UTC), nextExecution.get());

Optional<ZonedDateTime> lastExecution = execution.lastExecution(currentDateTime);
assertTrue(lastExecution.isPresent());
assertEquals(ZonedDateTime.of(LocalDate.of(2013, 3, 1), LocalTime.MIDNIGHT, ZoneOffset.UTC), lastExecution.get());

lastExecution = execution.lastExecution(nextExecution.get());
assertTrue(lastExecution.isPresent());
assertEquals(ZonedDateTime.of(LocalDate.of(2013, 3, 1), LocalTime.MIDNIGHT, ZoneOffset.UTC), lastExecution.get());
}
}

0 comments on commit 2302af5

Please sign in to comment.