SlaCheckerService { @Transactional void closeIncidents() { logger.debug("Close incidents (there should be only one)"); DateTime closedDate = dateTimeUtils.now(); List<SlaIncident> findByIsNullClosedDate = slaIncidentRepository.findByClosedDateIsNull(); for (SlaIncident ooSLAIncident : findByIsNullClosedDate) { ooSLAIncident.setClosedDate(closedDate); } slaIncidentRepository.saveAll(findByIsNullClosedDate); }    }
@Test public void testCloseIncidents() { List<SlaIncident> incidentIn = Arrays.asList(mock(SlaIncident.class), mock(SlaIncident.class)); List<SlaIncident> incidentOut = Arrays.asList(mock(SlaIncident.class), mock(SlaIncident.class)); DateTime now = new DateTime(); doReturn(now).when(dateTimeUtils).now(); doReturn(incidentIn).when(slaIncidentRepository).findByClosedDateIsNull(); doReturn(incidentOut).when(slaIncidentRepository).saveAll(incidentIn); slaCheckerService.closeIncidents(); verify(slaIncidentRepository).saveAll(incidentIn); for (SlaIncident slaIncident : incidentIn) { verify(slaIncident).setClosedDate(now); } }