@Test public void GetFormattedErrorMessageForDisplay_WithMessageOrThrowableMissing(){ String message = "An error occurred.\r\n220 ----------------- There was a problem\r\nNo username specified.\r\nServer not configured properly."; String expected = "<b>An error occurred.<br />220 ----------------- There was a problem<br />No username specified.<br />Server not configured properly.</b> <br /><br />"; assertThat("Message formatted even without exception object", Dialogs.getFormattedErrorMessageForDisplay(message, null), is(expected)); expected = ""; assertThat("Null message handled gracefully", Dialogs.getFormattedErrorMessageForDisplay(null, null), is(expected)); Throwable t = new Throwable((String)null); assertThat("Null message handled gracefully", Dialogs.getFormattedErrorMessageForDisplay(null, 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);  }