@Test public void testSendEmailError() throws MessagingException, IOException { long incidentId = 0L; String message = "some message"; MailException mailException = mock(MailException.class); doThrow(mailException).when(emailSender).send(any(MimeMessage.class)); SlaCheckerEmailService.logger = mock(Logger.class); slaCheckerEmailService.sendEmail(incidentId, message); verify(SlaCheckerEmailService.logger).error("Can't send OOSLA email", mailException); }
void sendEmail(long incidentId, String message) { MimeMessage mailMessage = emailSender.createMimeMessage(); try { mailMessage.setSubject(getSubject(incidentId), StandardCharsets.UTF_8.toString()); MimeMessageHelper helper = new MimeMessageHelper(mailMessage, true, StandardCharsets.UTF_8.toString()); helper.setFrom(slaCheckerEmailConfig.getFrom()); helper.setTo(slaCheckerEmailConfig.getTo()); helper.setText(message, true); emailSender.send(mailMessage); } catch (Exception ex) { logger.error("Can't send OOSLA email", ex); } }
SlaCheckerEmailService { void sendEmail(long incidentId, String message) { MimeMessage mailMessage = emailSender.createMimeMessage(); try { mailMessage.setSubject(getSubject(incidentId), StandardCharsets.UTF_8.toString()); MimeMessageHelper helper = new MimeMessageHelper(mailMessage, true, StandardCharsets.UTF_8.toString()); helper.setFrom(slaCheckerEmailConfig.getFrom()); helper.setTo(slaCheckerEmailConfig.getTo()); helper.setText(message, true); emailSender.send(mailMessage); } catch (Exception ex) { logger.error("Can't send OOSLA email", ex); } } }
SlaCheckerEmailService { void sendEmail(long incidentId, String message) { MimeMessage mailMessage = emailSender.createMimeMessage(); try { mailMessage.setSubject(getSubject(incidentId), StandardCharsets.UTF_8.toString()); MimeMessageHelper helper = new MimeMessageHelper(mailMessage, true, StandardCharsets.UTF_8.toString()); helper.setFrom(slaCheckerEmailConfig.getFrom()); helper.setTo(slaCheckerEmailConfig.getTo()); helper.setText(message, true); emailSender.send(mailMessage); } catch (Exception ex) { logger.error("Can't send OOSLA email", ex); } }  }
SlaCheckerEmailService { void sendEmail(long incidentId, String message) { MimeMessage mailMessage = emailSender.createMimeMessage(); try { mailMessage.setSubject(getSubject(incidentId), StandardCharsets.UTF_8.toString()); MimeMessageHelper helper = new MimeMessageHelper(mailMessage, true, StandardCharsets.UTF_8.toString()); helper.setFrom(slaCheckerEmailConfig.getFrom()); helper.setTo(slaCheckerEmailConfig.getTo()); helper.setText(message, true); emailSender.send(mailMessage); } catch (Exception ex) { logger.error("Can't send OOSLA email", ex); } }  void sendCloseIncidentEmail(long incidentId); void sendOpenIncidentEmail(long incidentId, List<Repository> ooslaRepositories); boolean shouldResendEmail(DateTime previousEmailDateTime); }
SlaCheckerEmailService { void sendEmail(long incidentId, String message) { MimeMessage mailMessage = emailSender.createMimeMessage(); try { mailMessage.setSubject(getSubject(incidentId), StandardCharsets.UTF_8.toString()); MimeMessageHelper helper = new MimeMessageHelper(mailMessage, true, StandardCharsets.UTF_8.toString()); helper.setFrom(slaCheckerEmailConfig.getFrom()); helper.setTo(slaCheckerEmailConfig.getTo()); helper.setText(message, true); emailSender.send(mailMessage); } catch (Exception ex) { logger.error("Can't send OOSLA email", ex); } }  void sendCloseIncidentEmail(long incidentId); void sendOpenIncidentEmail(long incidentId, List<Repository> ooslaRepositories); boolean shouldResendEmail(DateTime previousEmailDateTime);  }