DrishtiSMSService { public void sendSMS(String recipient, String message) { auditor.audit(SMS).with("recipient", recipient).with("message", message).with("smsIsSent", String.valueOf(canSendSMSes)).done(); logger.info(format("SMS {2}sent to {0}: {1}", recipient, message, canSendSMSes ? "" : "NOT ")); if (canSendSMSes) { smsService.sendSMS(recipient, message); } } @Autowired  DrishtiSMSService(SmsService smsService, Auditor auditor, @Value("#{drishti['sms.can.be.sent']}") boolean defaultValueForWhetherSMSCanBeSent); void sendSMS(String recipient, String message); void canSendSMSes(boolean value);  }
@Test public void shouldAuditTheSMSMessageThatWasSent() { DrishtiSMSService drishtiSMSService = new DrishtiSMSService(smsService, auditor, true); drishtiSMSService.sendSMS("9845700000", "Some message"); verify(messageBuilder).with("recipient", "9845700000"); verify(messageBuilder).with("message", "Some message"); verify(messageBuilder).with("smsIsSent", "true"); }
@Test public void shouldAuditEvenWhenTheSMSMessageWasNotSent() { DrishtiSMSService drishtiSMSService = new DrishtiSMSService(smsService, auditor, false); drishtiSMSService.sendSMS("9845700000", "Some message"); verify(messageBuilder).with("recipient", "9845700000"); verify(messageBuilder).with("message", "Some message"); verify(messageBuilder).with("smsIsSent", "false"); }