ProjectUpdater implements ScheduledJob { @Override public void execute(LocalDateTime lastExecuteTime) throws Exception { var projects = projectReader.getAllProjectsSince(lastExecuteTime); normalizeAndSave(projects); } @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 executeWithTimeSavesAllProjectsSince() throws Exception { var lastExecuteTime = LocalDateTime.now(clock); var expectedProjects = List.of(projectMock); given(projectReaderMock.getAllProjectsSince(lastExecuteTime)) .willReturn(expectedProjects); given(normalizerMock.normalize(expectedProjects)) .willReturn(expectedProjects); projectUpdater.execute(lastExecuteTime); verify(projectServiceMock).saveAll(projectListCaptor.capture()); var actualProjects = projectListCaptor.getValue(); assertThat(actualProjects).containsExactlyElementsOf(expectedProjects); }
@Test public void executeSavesInitialProjects() throws Exception { var expectedProjects = List.of(projectMock); given(projectReaderMock.getInitialProjects()) .willReturn(expectedProjects); given(normalizerMock.normalize(expectedProjects)) .willReturn(expectedProjects); projectUpdater.execute(); verify(projectServiceMock).saveAll(projectListCaptor.capture()); var actualProjects = projectListCaptor.getValue(); assertThat(actualProjects).containsExactlyElementsOf(expectedProjects); }