EmailAlertMessageBuilder { public static String buildCriticalMsgContent( String errorDetails, Throwable exception, String botId, String botName, String adapterName) { final StringBuilder msgContent = new StringBuilder("A CRITICAL error event has occurred on BX-bot."); msgContent.append(NEWLINE).append(NEWLINE); msgContent.append(HORIZONTAL_RULE); msgContent.append("Bot Id / Name:"); msgContent.append(NEWLINE).append(NEWLINE); msgContent.append(botId); msgContent.append(" / "); msgContent.append(botName); msgContent.append(NEWLINE).append(NEWLINE); msgContent.append(HORIZONTAL_RULE); msgContent.append("Exchange Adapter:"); msgContent.append(NEWLINE).append(NEWLINE); msgContent.append(adapterName); msgContent.append(NEWLINE).append(NEWLINE); msgContent.append(HORIZONTAL_RULE); msgContent.append("Event Time:"); msgContent.append(NEWLINE).append(NEWLINE); msgContent.append(new Date()); msgContent.append(NEWLINE).append(NEWLINE); msgContent.append(HORIZONTAL_RULE); msgContent.append("Event Details:"); msgContent.append(NEWLINE).append(NEWLINE); msgContent.append(errorDetails); msgContent.append(NEWLINE).append(NEWLINE); msgContent.append(HORIZONTAL_RULE); msgContent.append("Action Taken:"); msgContent.append(NEWLINE).append(NEWLINE); msgContent.append("The bot will shut down NOW! Check the bot logs for more information."); msgContent.append(NEWLINE).append(NEWLINE); if (exception != null) { msgContent.append(HORIZONTAL_RULE); msgContent.append("Stacktrace:"); msgContent.append(NEWLINE).append(NEWLINE); final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); exception.printStackTrace(printWriter); msgContent.append(stringWriter.toString()); } return msgContent.toString(); } private  EmailAlertMessageBuilder(); static String buildCriticalMsgContent(
      String errorDetails, Throwable exception, String botId, String botName, String adapterName);  }
@Test public void testBuildingCriticalMsgContent() { final String expectedStartOfMsg = "A CRITICAL error event has occurred on BX-bot." + NEWLINE + NEWLINE + "--------------------------------------------------" + NEWLINE + "Bot Id / Name:" + NEWLINE + NEWLINE + "seti-alpha-3 / The Pioneer" + NEWLINE + NEWLINE + "--------------------------------------------------" + NEWLINE + "Exchange Adapter:" + NEWLINE + NEWLINE + "Bitstamp" + NEWLINE + NEWLINE + "--------------------------------------------------" + NEWLINE + "Event Time:" + NEWLINE + NEWLINE; final String expectedMiddleOfMsg = NEWLINE + "--------------------------------------------------" + NEWLINE + "Event Details:" + NEWLINE + NEWLINE + "The trouble with Tribbles..." + NEWLINE + NEWLINE + "--------------------------------------------------" + NEWLINE + "Action Taken:" + NEWLINE + NEWLINE + "The bot will shut down NOW! Check the bot logs for more information." + NEWLINE + NEWLINE + "--------------------------------------------------" + NEWLINE + "Stacktrace:" + NEWLINE; final String errorMsg = "The trouble with Tribbles..."; final Exception exception = new RuntimeException(errorMsg); final String botId = "seti-alpha-3"; final String botName = "The Pioneer"; final String adapterName = "Bitstamp"; final String msgContent = EmailAlertMessageBuilder.buildCriticalMsgContent( errorMsg, exception, botId, botName, adapterName); assertTrue(msgContent.startsWith(expectedStartOfMsg)); assertTrue(msgContent.contains(expectedMiddleOfMsg)); }