SlaCheckerService { void checkWithOpenIncident(SlaIncident openIncident) { logger.debug("An incident is open, check for status update"); List<Repository> ooslaRepositories = repositoryRepository.findByDeletedFalseAndCheckSLATrueAndRepositoryStatisticOoslaTextUnitCountGreaterThanOrderByNameAsc(0L); if (ooslaRepositories.isEmpty()) { logger.debug("No repositories out of SLA, close incident and send email"); closeIncidents(); slaCheckerEmailService.sendCloseIncidentEmail(openIncident.getId()); } else { if (slaCheckerEmailService.shouldResendEmail(openIncident.getCreatedDate())) { logger.debug("Still ouf of SLA, resending email"); slaCheckerEmailService.sendOpenIncidentEmail(openIncident.getId(), ooslaRepositories); } else { logger.debug("Still ouf of SLA, no need to resend email for now"); } } }    }
@Test public void testCheckWithOpenIncidentResend() { SlaIncident openIncident = getSlaIncidentForTest(); List<Repository> repositories = getRepositoriesForTest(); doReturn(repositories).when(repositoryRepository).findByDeletedFalseAndCheckSLATrueAndRepositoryStatisticOoslaTextUnitCountGreaterThanOrderByNameAsc(0L); doReturn(true).when(slaCheckerEmailService).shouldResendEmail(openIncident.getCreatedDate()); slaCheckerService.checkWithOpenIncident(openIncident); verify(slaCheckerEmailService).sendOpenIncidentEmail(openIncident.getId(), repositories); }
@Test public void testCheckWithOpenIncidentDoNothing() { SlaIncident openIncident = getSlaIncidentForTest(); List<Repository> repositories = getRepositoriesForTest(); doReturn(repositories).when(repositoryRepository).findByDeletedFalseAndCheckSLATrueAndRepositoryStatisticOoslaTextUnitCountGreaterThanOrderByNameAsc(0L); doReturn(false).when(slaCheckerEmailService).shouldResendEmail(openIncident.getCreatedDate()); slaCheckerService.checkWithOpenIncident(openIncident); verify(slaCheckerEmailService, never()).sendOpenIncidentEmail(openIncident.getId(), repositories); }