Last active
July 3, 2024 01:21
-
-
Save JonasGroeger/4c73439059fdc629977bf58ed0fd17a5 to your computer and use it in GitHub Desktop.
Spring Cron Expression Tester (Junit 5)
This file contains hidden or 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
package de.jonasgroeger; | |
import org.junit.jupiter.api.Test; | |
import org.springframework.scheduling.support.CronExpression; | |
import java.time.LocalDateTime; | |
import java.time.ZoneId; | |
class SpringCronExpressionTester { | |
private final ZoneId timezone = ZoneId.of("Europe/Berlin"); | |
@Test | |
void testCron() { | |
String cronExpression = "0 0 1 * * *"; | |
int MAX_RUNS = 50; | |
CronExpression generator = CronExpression.parse(cronExpression); | |
LocalDateTime now = LocalDateTime.now(timezone); | |
for (int i = 0; i < MAX_RUNS; i++) { | |
LocalDateTime nextRun = generator.next(now); | |
System.out.println(nextRun); | |
now = nextRun; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated for JUnit 5!