/** * creates and sends an Email to the given emailReceipients * * @param subject * @param content * @param emailReceipients * @return * @throws MessagingException */ public boolean createAndSendMail(String subject, String content, Address[] emailReceipients) throws MessagingException{ boolean deliverEmails = ConfigurationService.getPropertyAsBoolean(ConfigKey.DELIVER_MAIL, true); // deliverEmails is active and emailReceipients are available if (deliverEmails && emailReceipients != null && emailReceipients.length > 0) { return mailService.createMessageAndSend(subject, content, emailReceipients); } return false; } }
@Test public void test_createMessageAndSend_logging_Empty() throws MessagingException { // given // Mail Session is null Address[] to = new InternetAddress[0]; // when mailService.createMessageAndSend("subject", "content", to); // then verify(log, times(1)).warning("Mail session not available, unable to send Mail(subject: subject, content: content ) to Receipients: "); }
@Test public void test_createMessageAndSend_logging_null() throws MessagingException { // given // Mail Session is null // when mailService.createMessageAndSend("subject", "content", null); // then verify(log, times(1)).warning("Mail session not available, unable to send Mail(subject: subject, content: content ) to Receipients: "); }
@Test public void test_createMessageAndSend_logging() throws MessagingException { // given // Mail Session is null Address[] to = new InternetAddress[1]; to[0] = new InternetAddress("test@test.ch"); // when mailService.createMessageAndSend("subject", "content", to); // then verify(log, times(1)).warning("Mail session not available, unable to send Mail(subject: subject, content: content ) to Receipients: test@test.ch, "); }
@Test public void test_createAndSendMail_ok() throws MessagingException { // given Address[] to = new InternetAddress[1]; to[0] = new InternetAddress("test@test.ch"); when(mailService.createMessageAndSend("subject", "content", to)).thenReturn(true); // when boolean result = notificationService.createAndSendMail("subject", "content", to); // then verify(mailService, times(1)).createMessageAndSend("subject", "content", to); assertTrue(result); }
@Test public void test_createAndSendMail_nok() throws MessagingException { // given Address[] to = new InternetAddress[1]; to[0] = new InternetAddress("test@test.ch"); when(mailService.createMessageAndSend("subject", "content", to)).thenReturn(false); // when boolean result = notificationService.createAndSendMail("subject", "content", to); // then verify(mailService, times(1)).createMessageAndSend("subject", "content", to); assertFalse(result); }