@Test public void updateDefectAssignations_should_keep_a_problem_without_closing_date_for_a_nonexistent_defect() { Problem problem = new Problem() .withDefectId("1") .withDefectExistence(DefectExistence.NONEXISTENT) .withStatus(ProblemStatus.OPEN) .withClosingDateTime(new Date()); List<Problem> problems = Collections.singletonList(problem); List<Defect> statuses = Collections.emptyList(); doReturn(null).when(problemRepository).saveAll(problemListArgument.capture()); cut.updateDefectAssignations(problems, statuses); assertThat(problemListArgument.getValue()).hasSameElementsAs(problems); assertThat(problem.getDefectExistence()).isEqualTo(DefectExistence.NONEXISTENT); assertThat(problem.getStatus()).isEqualTo(ProblemStatus.OPEN); assertThat(problem.getClosingDateTime()).isNull(); }
void updateDefectAssignations(List<Problem> problems, List<Defect> statuses) { final List<Problem> problemsToUpdate = new ArrayList<>(); for (Problem problem : problems) { final Optional<Defect> defect = statuses.stream() .filter(d -> problem.getDefectId().equals(d.getId())) .findFirst(); if (defect.isPresent()) { if (problem.getDefectExistence() != DefectExistence.EXISTS || problem.getStatus() != defect.get().getStatus() || !areEqualDownToSeconds(problem.getClosingDateTime(), defect.get().getCloseDateTime())) { problem.setDefectExistence(DefectExistence.EXISTS); problem.setStatus(defect.get().getStatus()); problem.setClosingDateTime(defect.get().getCloseDateTime()); problemsToUpdate.add(problem); } } else { if (problem.getDefectExistence() != DefectExistence.NONEXISTENT || problem.getStatus() != ProblemStatus.OPEN || problem.getClosingDateTime() != null) { problem.setDefectExistence(DefectExistence.NONEXISTENT); problem.setStatus(ProblemStatus.OPEN); problem.setClosingDateTime(null); problemsToUpdate.add(problem); } } } problemRepository.saveAll(problemsToUpdate); }
DefectService { void updateDefectAssignations(List<Problem> problems, List<Defect> statuses) { final List<Problem> problemsToUpdate = new ArrayList<>(); for (Problem problem : problems) { final Optional<Defect> defect = statuses.stream() .filter(d -> problem.getDefectId().equals(d.getId())) .findFirst(); if (defect.isPresent()) { if (problem.getDefectExistence() != DefectExistence.EXISTS || problem.getStatus() != defect.get().getStatus() || !areEqualDownToSeconds(problem.getClosingDateTime(), defect.get().getCloseDateTime())) { problem.setDefectExistence(DefectExistence.EXISTS); problem.setStatus(defect.get().getStatus()); problem.setClosingDateTime(defect.get().getCloseDateTime()); problemsToUpdate.add(problem); } } else { if (problem.getDefectExistence() != DefectExistence.NONEXISTENT || problem.getStatus() != ProblemStatus.OPEN || problem.getClosingDateTime() != null) { problem.setDefectExistence(DefectExistence.NONEXISTENT); problem.setStatus(ProblemStatus.OPEN); problem.setClosingDateTime(null); problemsToUpdate.add(problem); } } } problemRepository.saveAll(problemsToUpdate); } }
DefectService { void updateDefectAssignations(List<Problem> problems, List<Defect> statuses) { final List<Problem> problemsToUpdate = new ArrayList<>(); for (Problem problem : problems) { final Optional<Defect> defect = statuses.stream() .filter(d -> problem.getDefectId().equals(d.getId())) .findFirst(); if (defect.isPresent()) { if (problem.getDefectExistence() != DefectExistence.EXISTS || problem.getStatus() != defect.get().getStatus() || !areEqualDownToSeconds(problem.getClosingDateTime(), defect.get().getCloseDateTime())) { problem.setDefectExistence(DefectExistence.EXISTS); problem.setStatus(defect.get().getStatus()); problem.setClosingDateTime(defect.get().getCloseDateTime()); problemsToUpdate.add(problem); } } else { if (problem.getDefectExistence() != DefectExistence.NONEXISTENT || problem.getStatus() != ProblemStatus.OPEN || problem.getClosingDateTime() != null) { problem.setDefectExistence(DefectExistence.NONEXISTENT); problem.setStatus(ProblemStatus.OPEN); problem.setClosingDateTime(null); problemsToUpdate.add(problem); } } } problemRepository.saveAll(problemsToUpdate); }  }
DefectService { void updateDefectAssignations(List<Problem> problems, List<Defect> statuses) { final List<Problem> problemsToUpdate = new ArrayList<>(); for (Problem problem : problems) { final Optional<Defect> defect = statuses.stream() .filter(d -> problem.getDefectId().equals(d.getId())) .findFirst(); if (defect.isPresent()) { if (problem.getDefectExistence() != DefectExistence.EXISTS || problem.getStatus() != defect.get().getStatus() || !areEqualDownToSeconds(problem.getClosingDateTime(), defect.get().getCloseDateTime())) { problem.setDefectExistence(DefectExistence.EXISTS); problem.setStatus(defect.get().getStatus()); problem.setClosingDateTime(defect.get().getCloseDateTime()); problemsToUpdate.add(problem); } } else { if (problem.getDefectExistence() != DefectExistence.NONEXISTENT || problem.getStatus() != ProblemStatus.OPEN || problem.getClosingDateTime() != null) { problem.setDefectExistence(DefectExistence.NONEXISTENT); problem.setStatus(ProblemStatus.OPEN); problem.setClosingDateTime(null); problemsToUpdate.add(problem); } } } problemRepository.saveAll(problemsToUpdate); }  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); }
DefectService { void updateDefectAssignations(List<Problem> problems, List<Defect> statuses) { final List<Problem> problemsToUpdate = new ArrayList<>(); for (Problem problem : problems) { final Optional<Defect> defect = statuses.stream() .filter(d -> problem.getDefectId().equals(d.getId())) .findFirst(); if (defect.isPresent()) { if (problem.getDefectExistence() != DefectExistence.EXISTS || problem.getStatus() != defect.get().getStatus() || !areEqualDownToSeconds(problem.getClosingDateTime(), defect.get().getCloseDateTime())) { problem.setDefectExistence(DefectExistence.EXISTS); problem.setStatus(defect.get().getStatus()); problem.setClosingDateTime(defect.get().getCloseDateTime()); problemsToUpdate.add(problem); } } else { if (problem.getDefectExistence() != DefectExistence.NONEXISTENT || problem.getStatus() != ProblemStatus.OPEN || problem.getClosingDateTime() != null) { problem.setDefectExistence(DefectExistence.NONEXISTENT); problem.setStatus(ProblemStatus.OPEN); problem.setClosingDateTime(null); problemsToUpdate.add(problem); } } } problemRepository.saveAll(problemsToUpdate); }  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);  }