@Test public void GetFormattedErrorMessageForDisplay_WithMessageAndThrowable() { String message = "An error occurred.\r\n220 ----------------- There was a problem\r\nNo username specified.\r\nServer not configured properly."; Throwable t = new Throwable("Parameter not set.\r\nException handling not configured.\r\nEat oranges they are great.\r\n"); t.setStackTrace(new StackTraceElement[]{new StackTraceElement("XXX", "yyy", "BBB", 99)}); String expected = "<b>An error occurred.<br />220 ----------------- There was a problem<br />No username specified.<br />Server not configured properly.</b> <br /><br />Parameter not set.<br />Exception handling not configured.<br />Eat oranges they are great.<br /><br /><br />"; assertThat("Message formatted for error display", Dialogs.getFormattedErrorMessageForDisplay(message, t), is(expected)); }
protected static String getFormattedErrorMessageForDisplay(String message, Throwable throwable) { StringBuilder html = new StringBuilder(); if(!Strings.isNullOrEmpty(message)){ html.append("<b>").append(message.replace("\r\n","<br />") .replace("\n","<br />")).append("</b> <br /><br />"); } while(throwable != null && !Strings.isNullOrEmpty(throwable.getMessage())){ html.append(throwable.getMessage().replace("\r\n","<br />")) .append("<br /><br />"); throwable=throwable.getCause(); } return html.toString(); }
Dialogs { protected static String getFormattedErrorMessageForDisplay(String message, Throwable throwable) { StringBuilder html = new StringBuilder(); if(!Strings.isNullOrEmpty(message)){ html.append("<b>").append(message.replace("\r\n","<br />") .replace("\n","<br />")).append("</b> <br /><br />"); } while(throwable != null && !Strings.isNullOrEmpty(throwable.getMessage())){ html.append(throwable.getMessage().replace("\r\n","<br />")) .append("<br /><br />"); throwable=throwable.getCause(); } return html.toString(); } }
Dialogs { protected static String getFormattedErrorMessageForDisplay(String message, Throwable throwable) { StringBuilder html = new StringBuilder(); if(!Strings.isNullOrEmpty(message)){ html.append("<b>").append(message.replace("\r\n","<br />") .replace("\n","<br />")).append("</b> <br /><br />"); } while(throwable != null && !Strings.isNullOrEmpty(throwable.getMessage())){ html.append(throwable.getMessage().replace("\r\n","<br />")) .append("<br /><br />"); throwable=throwable.getCause(); } return html.toString(); }  }
Dialogs { protected static String getFormattedErrorMessageForDisplay(String message, Throwable throwable) { StringBuilder html = new StringBuilder(); if(!Strings.isNullOrEmpty(message)){ html.append("<b>").append(message.replace("\r\n","<br />") .replace("\n","<br />")).append("</b> <br /><br />"); } while(throwable != null && !Strings.isNullOrEmpty(throwable.getMessage())){ html.append(throwable.getMessage().replace("\r\n","<br />")) .append("<br /><br />"); throwable=throwable.getCause(); } return html.toString(); }  static void error(String title, final String friendlyMessage, final String errorMessage, final Throwable throwable, final Context context); static void alert(String title, String message, Context context); static void alert(String title, String message, Context context, final MessageBoxCallback msgCallback); static void alert(String title, String message, Context context, boolean includeCancel, final MessageBoxCallback msgCallback); static void progress(Context context, String title, String message); static void hideProgress(); static void autoCompleteText(final Context ctx, final String cacheKey, String title,
                                        String hint, String text,
                                        final AutoCompleteCallback callback); }
Dialogs { protected static String getFormattedErrorMessageForDisplay(String message, Throwable throwable) { StringBuilder html = new StringBuilder(); if(!Strings.isNullOrEmpty(message)){ html.append("<b>").append(message.replace("\r\n","<br />") .replace("\n","<br />")).append("</b> <br /><br />"); } while(throwable != null && !Strings.isNullOrEmpty(throwable.getMessage())){ html.append(throwable.getMessage().replace("\r\n","<br />")) .append("<br /><br />"); throwable=throwable.getCause(); } return html.toString(); }  static void error(String title, final String friendlyMessage, final String errorMessage, final Throwable throwable, final Context context); static void alert(String title, String message, Context context); static void alert(String title, String message, Context context, final MessageBoxCallback msgCallback); static void alert(String title, String message, Context context, boolean includeCancel, final MessageBoxCallback msgCallback); static void progress(Context context, String title, String message); static void hideProgress(); static void autoCompleteText(final Context ctx, final String cacheKey, String title,
                                        String hint, String text,
                                        final AutoCompleteCallback callback);  }