AlertService { String message(Alert alert, int alertCountSinceLastSent) { String docURL = docURL(alert.kibanaIndex, alert.id); var builder = new StringBuilder(256); if (alertCountSinceLastSent > 0) builder.append("*[").append(alertCountSinceLastSent).append("]* "); builder.append(alert.severity).append(": *"); if (site != null) builder.append(site).append(" / "); builder.append(alert.app).append("*\n"); if (alert.host != null) builder.append("host: ").append(alert.host).append('\n'); builder.append("_id: <").append(docURL).append('|').append(alert.id).append(">\n"); if (alert.action != null) builder.append("action: ").append(alert.action).append('\n'); builder.append("error_code: *").append(alert.errorCode).append("*\nmessage: ").append(alert.errorMessage).append('\n'); return builder.toString(); } AlertService(AlertConfig config); void process(Alert alert);  }
@Test void message() { Alert alert = alert(Severity.WARN, "ERROR_CODE", "trace"); alert.id = "id"; alert.errorMessage = "message"; alert.kibanaIndex = "action"; assertThat(service.message(alert, 10)).isEqualTo(""" *[10]* WARN: *site / website* _id: <http: error_code: *ERROR_CODE* message: message """); alert.host = "host"; assertThat(service.message(alert, 0)).isEqualTo(""" WARN: *site / website* host: host _id: <http: error_code: *ERROR_CODE* message: message """); alert.action = "action"; alert.host = null; assertThat(service.message(alert, 0)).isEqualTo(""" WARN: *site / website* _id: <http: action: action error_code: *ERROR_CODE* message: message """); } private Alert alert(Severity severity, String errorCode, String index) { var alert = new Alert(); alert.app = "website"; alert.severity = severity; alert.errorCode = errorCode; alert.kibanaIndex = index; return alert; }