Skip to content

Commit

Permalink
Fixed test for jmrozanec#363. Added test for intended expression.
Browse files Browse the repository at this point in the history
  • Loading branch information
pangyikhei committed Oct 5, 2019
1 parent f68dca8 commit 41a9cb8
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/test/java/com/cronutils/Issue363Test.java
Expand Up @@ -15,9 +15,39 @@

public class Issue363Test {

//@Test
public void quartzNextExecutionTime() {
@Test
public void everySecondOfMinute01Test() {
// every second of the first minute of every hour/day/year
String cronExpression = "* 1 * * * ?";
CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
ExecutionTime executionTime = ExecutionTime.forCron(parser.parse(cronExpression));

ZonedDateTime now = ZonedDateTime.of(2019, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(now);

assertTrue(nextExecution.isPresent());
// First match should be 2019-01-01T00:01:00Z
ZonedDateTime expectedTime = ZonedDateTime.of(2019, 1, 1, 0, 1, 0, 0, ZoneOffset.UTC);
assertEquals(expectedTime, nextExecution.get());

// Should also match the next 59 seconds
for (int i = 1; i <= 59; i++) {
nextExecution = executionTime.nextExecution(nextExecution.get());
assertTrue(nextExecution.isPresent());
assertEquals(expectedTime.plusSeconds(i), nextExecution.get());
}

// After the every second of 00:01, it the next execution should be at 01:01:00Z
nextExecution = executionTime.nextExecution(ZonedDateTime.of(2019, 1, 1, 0, 1, 59, 0, ZoneOffset.UTC));
assertTrue(nextExecution.isPresent());
expectedTime = ZonedDateTime.of(2019, 1, 1, 1, 1, 0, 0, ZoneOffset.UTC);
assertEquals(expectedTime, nextExecution.get());
}

@Test
public void everyMinute01Test() {
// every minute 1 of every hour/day/year
String cronExpression = "0 1 * * * ?";
ZonedDateTime now = ZonedDateTime.of(2019, 1, 1, 0, 1, 0, 0, ZoneOffset.UTC);
CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));

Expand Down

0 comments on commit 41a9cb8

Please sign in to comment.