I have a scheduled task in a spring boot application:
@Scheduled(fixedRateString = "${scheduled.task.rate}")
public void runScheduledTask() {
// ...
}
With a corresponding test:
@Test
public void test_scheduledTask_runs() {
await().atMost(Duration.ofMillis(scheduledTaskRate).multipliedBy(2)).untilAsserted(() -> {
Mockito.verify(scheduledTasks, Mockito.atLeastOnce()).runScheduledTask();
});
}
Now I want to use a cron instead of a fixed rate:
@Scheduled(cron = "${scheduled.task.cron}")
Now I need to adapt the test to this. How do get a Duration object corresponding to the frequency of the cron expression?