-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #450 from IndeedSi/402-add-test-case
#402: add a test case for the issue
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |