ConfirmationServiceImpl extends CoreBaseService<ConfirmationServiceMetric<ConfirmationServiceContext>, ConfirmationServiceContext> implements
        ConfirmationService { @Override @Retryable public boolean sendMessage(MailMessage message) throws InvalidAddressException { boolean delivered = false; if (message.hasCC() && !message.getToEmailAddresses().contains(message.getCCEmailAddress())) { delivered = sendToOneRecipient(message, message.getCCEmailAddress()); } message.setNoCC(); List<String> toEmailAddresses = message.getToEmailAddresses(); for (String toEmailAddress : toEmailAddresses) { delivered = sendToOneRecipient(message, toEmailAddress); } return delivered; }  @Override boolean sendConfirmation(ConfirmationInfo confirmationInfo); @Override @Retryable boolean sendMessage(MailMessage message);  }
@Test public void testMetrics_sendMessage_OneMessage() { setNewMetrics(); try { boolean isSent = confirmationServiceImpl.sendMessage(mailMessageMock); assertTrue("send message should be successful", isSent); double successRate = getSuccessRate(); assertEquals(1.0, successRate, 0); assertEquals(1, getAllSent()); assertEquals(0, getSentFailed()); } catch (InvalidAddressException e) { e.printStackTrace(); } }
@Test public void testMetrics_sendMessage_invalidAddress() { setNewMetrics(); try { confirmationServiceImpl.sendMessage(mailMessageMock_nok); } catch (InvalidAddressException e) { double successRate = getSuccessRate(); assertEquals(0.0, successRate, 0); assertEquals(1, getAllSent()); assertEquals(1, getSentFailed()); } }
@Test public void testMetrics_sendMessageToTwoRecipients() { setNewMetrics(); try { boolean isSent = confirmationServiceImpl.sendMessage(mailMessageWithTwoRecipientsMock); assertTrue("last sent message should be successful", isSent); double successRate = getSuccessRate(); assertEquals(0.5, successRate, 0); assertEquals(2, getAllSent()); assertEquals(1, getSentFailed()); } catch (InvalidAddressException e) { } }