ConfirmationServiceImpl extends CoreBaseService<ConfirmationServiceMetric<ConfirmationServiceContext>, ConfirmationServiceContext> implements
        ConfirmationService { @Override public boolean sendConfirmation(ConfirmationInfo confirmationInfo) { boolean delivered = false; try { delivered = confirmationDelegate.send(confirmationInfo); } catch (Exception e) { LOG.error("Could not send confirmation for: " + confirmationInfo); delivered = false; } finally { notifyMetrics(delivered); } return delivered; }  @Override boolean sendConfirmation(ConfirmationInfo confirmationInfo); @Override @Retryable boolean sendMessage(MailMessage message);  }
@Test public void testMetrics_sendConfirmation_OnceSuccessful() { setNewMetrics(); boolean isSent = confirmationServiceImpl.sendConfirmation(confirmationInfoMock_sent); assertTrue("send confirmation should be successful", isSent); double successRate = getSuccessRate(); assertEquals(1.0, successRate, 0); assertEquals(1, getAllSent()); assertEquals(0, getSentFailed()); }
@Test public void testMetrics_sendConfirmation_OnceSuccessful_OnceUnsuccessful() { setNewMetrics(); boolean isSent = confirmationServiceImpl.sendConfirmation(confirmationInfoMock_sent); assertTrue("send confirmation should be successful", isSent); confirmationServiceImpl.sendConfirmation(confirmationInfoMock_notSent); double successRate = getSuccessRate(); assertEquals(0.5, successRate, 0); assertEquals(2, getAllSent()); assertEquals(1, getSentFailed()); }
@Test public void testMetrics_sendConfirmation_TwiceUnsuccessful() { setNewMetrics(); boolean isSent = confirmationServiceImpl.sendConfirmation(confirmationInfoMock_notSent); assertFalse("send confirmation should be unsuccessful", isSent); confirmationServiceImpl.sendConfirmation(confirmationInfoMock_notSent); double successRate = getSuccessRate(); assertEquals(0, successRate, 0); assertEquals(2, getAllSent()); assertEquals(2, getSentFailed()); }