EmailAlertListenerSupport implements AlertListener { @Override public final void onAlert(AlertInfo alert, long actualCount) { LOG.debug("onAlert (" + alert.toHumanString() + ")"); String subject = StringUtils.isNotEmpty(alert.getNotificationSubject()) ? formatSubject(alert) : String.format(DEFAULT_ALERT_SUBJECT, alert.getId()); String body = StringUtils.isNotEmpty(alert.getNotificationBody()) ? formatBody(alert, actualCount) : String.format(DEFAULT_ALERT_BODY, actualCount, alert.getId(), alert.getLimit()); Assert.state(StringUtils.isNotEmpty(subject), "subject can't be empty"); Assert.state(StringUtils.isNotEmpty(body), "body can't be empty"); try { sendEmail(subject, body); } catch (Exception ex) { LOG.error("Error occurred during email sending for alert id=" + alert.getId(), ex); } try { doOnAlert(alert); } catch (Exception ex) { LOG.error("Error occurred during final action for alert id=" + alert.getId(), ex); } }  @Override boolean supports(AlertInfo alert); @Override final void onAlert(AlertInfo alert, long actualCount);  }
@Test public void testOnAlert() { String subject = "Alert: notification about WAITING messages"; String body = "There are %d message(s) in WAITING_FOR_RESPONSE state for more then %d seconds."; AlertInfo alert = new AlertInfo("ID", 1, "sql", true, subject, body); int actualCount = 3; alertListener.onAlert(alert, actualCount); verify(emailServiceMock, only()).sendEmailToAdmins(subject, alertListener.formatBody(alert, actualCount)); }