ProjectUpdater implements ScheduledJob { @Override public boolean shouldExecute(LocalDateTime lastExecuteTime) { Duration lastUpdateDeltaDuration = Duration.between(lastExecuteTime, LocalDateTime.now(clock)).abs(); return refreshIntervalDuration.compareTo(lastUpdateDeltaDuration) <= 0; } @Autowired(required = false)  ProjectUpdater(ProjectService projectService,
                          ProjectReader projectReader,
                          ProjectBoardConfigurationProperties properties,
                          @Lazy List<Normalizer<Project>> normalizers,
                          Clock clock); @Autowired(required = false)  ProjectUpdater(ProjectService projectService,
                          ProjectReader projectReader,
                          ProjectBoardConfigurationProperties properties,
                          Clock clock); @Override void execute(LocalDateTime lastExecuteTime); @Override void execute(); @Override String getJobIdentifier(); @Override boolean shouldExecute(LocalDateTime lastExecuteTime);  }
@Test public void shouldExecuteReturnsTrueWhenLastExecuteMoreThanRefreshIntervalMinutesAgo() { var minutesAgo = REFRESH_INTERVAL + 1L; var lastExecuteTime = LocalDateTime.now(clock).plus(minutesAgo, ChronoUnit.MINUTES); var actualShouldUpdate = projectUpdater.shouldExecute(lastExecuteTime); assertThat(actualShouldUpdate).isTrue(); }
@Test public void shouldExecuteReturnsTrueWhenLastExecuteExactlyRefreshIntervalMinutesAgo() { var lastExecuteTime = LocalDateTime.now(clock).plus(REFRESH_INTERVAL, ChronoUnit.MINUTES); var actualShouldUpdate = projectUpdater.shouldExecute(lastExecuteTime); assertThat(actualShouldUpdate).isTrue(); }
@Test public void shouldExecuteReturnsFalseWhenLastExecuteLessThanRefreshIntervalMinutesAgo() { var minutesAgo = REFRESH_INTERVAL - 1L; var lastExecuteTime = LocalDateTime.now(clock).plus(minutesAgo, ChronoUnit.MINUTES); var actualShouldUpdate = projectUpdater.shouldExecute(lastExecuteTime); assertThat(actualShouldUpdate).isFalse(); }