### Question:
DefectService { @Transactional public void incrementalIndex(Project project, DefectAdapter defectAdapter, Date since) throws FetchException { log.trace("Begin defect incremental indexing for updates since {} for project {}", since, project.getName()); final long projectId = project.getId(); final List<Problem> problems = problemRepository.findAllByProjectIdAndDefectIdIsNotEmpty(projectId); incrementalIndex(projectId, defectAdapter, since, problems); }  Optional<DefectAdapter> getAdapter(long projectId); List<DefectAdapter> getAdapters(); @Scheduled(fixedDelayString = "${ara.defectSyncSchedulingDelayInMilliseconds}", initialDelayString = "${ara.defectSyncSchedulingInitialDelayInMilliseconds}") @Transactional void updateStatuses(); @Transactional void fullIndex(Project project, DefectAdapter defectAdapter); @Transactional void incrementalIndex(Project project, DefectAdapter defectAdapter, Date since); @Transactional void refreshDefectExistences(long projectId);  }### Answer:
@Test public void incrementalIndex_should_update_problems_of_changed_defects() throws FetchException { final long aProjectId = 42; Project project = new Project().withId(Long.valueOf(aProjectId)); Date since = new Date(); final Problem updatedOpenProblem = new Problem().withDefectId("updated-open"); final Problem updatedClosedProblem = new Problem().withDefectId("updated-closed"); List<Problem> problemsWithDefects = Arrays.asList( new Problem().withDefectId(""), updatedOpenProblem, updatedClosedProblem, new Problem().withDefectId("not-updated")); when(problemRepository.findAllByProjectIdAndDefectIdIsNotEmpty(aProjectId)).thenReturn(problemsWithDefects); Date closeDate = new Date(); when(defectAdapter.getChangedDefects(eq(aProjectId), same(since))).thenReturn(Arrays.asList( new Defect("any1", ProblemStatus.OPEN, null), new Defect("updated-open", ProblemStatus.OPEN, null), new Defect("any2", ProblemStatus.CLOSED, closeDate), new Defect("updated-closed", ProblemStatus.CLOSED, closeDate))); doReturn(null).when(problemRepository).saveAll(problemListArgument.capture()); cut.incrementalIndex(project, defectAdapter, since); assertThat(problemListArgument.getValue()) .hasSameElementsAs(Arrays.asList(updatedOpenProblem, updatedClosedProblem)); assertThat(updatedOpenProblem.getDefectExistence()).isEqualTo(DefectExistence.EXISTS); assertThat(updatedOpenProblem.getStatus()).isEqualTo(ProblemStatus.OPEN); assertThat(updatedOpenProblem.getClosingDateTime()).isNull(); assertThat(updatedClosedProblem.getDefectExistence()).isEqualTo(DefectExistence.EXISTS); assertThat(updatedClosedProblem.getStatus()).isEqualTo(ProblemStatus.CLOSED); assertThat(updatedClosedProblem.getClosingDateTime()).isEqualTo(closeDate); }