Skip to content

Commit ee09682

Browse files
authored
Merge pull request #397 from pangyikhei/363-fix-tests
Fixed test for #363. Added test for intended expression.
2 parents 523785f + 41a9cb8 commit ee09682

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

src/test/java/com/cronutils/Issue363Test.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,39 @@
1515

1616
public class Issue363Test {
1717

18-
//@Test
19-
public void quartzNextExecutionTime() {
18+
@Test
19+
public void everySecondOfMinute01Test() {
20+
// every second of the first minute of every hour/day/year
2021
String cronExpression = "* 1 * * * ?";
22+
CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
23+
ExecutionTime executionTime = ExecutionTime.forCron(parser.parse(cronExpression));
24+
25+
ZonedDateTime now = ZonedDateTime.of(2019, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
26+
Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(now);
27+
28+
assertTrue(nextExecution.isPresent());
29+
// First match should be 2019-01-01T00:01:00Z
30+
ZonedDateTime expectedTime = ZonedDateTime.of(2019, 1, 1, 0, 1, 0, 0, ZoneOffset.UTC);
31+
assertEquals(expectedTime, nextExecution.get());
32+
33+
// Should also match the next 59 seconds
34+
for (int i = 1; i <= 59; i++) {
35+
nextExecution = executionTime.nextExecution(nextExecution.get());
36+
assertTrue(nextExecution.isPresent());
37+
assertEquals(expectedTime.plusSeconds(i), nextExecution.get());
38+
}
39+
40+
// After the every second of 00:01, it the next execution should be at 01:01:00Z
41+
nextExecution = executionTime.nextExecution(ZonedDateTime.of(2019, 1, 1, 0, 1, 59, 0, ZoneOffset.UTC));
42+
assertTrue(nextExecution.isPresent());
43+
expectedTime = ZonedDateTime.of(2019, 1, 1, 1, 1, 0, 0, ZoneOffset.UTC);
44+
assertEquals(expectedTime, nextExecution.get());
45+
}
46+
47+
@Test
48+
public void everyMinute01Test() {
49+
// every minute 1 of every hour/day/year
50+
String cronExpression = "0 1 * * * ?";
2151
ZonedDateTime now = ZonedDateTime.of(2019, 1, 1, 0, 1, 0, 0, ZoneOffset.UTC);
2252
CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
2353

0 commit comments

Comments
 (0)