@Test public void GetFormattedErrorMessageForPlainText_WithMessageOnly() { String message = "An error occurred.\r\n220 ----------------- There was a problem\r\nNo username specified.\r\nServer not configured properly."; String plainText = "An error occurred.\r\n220 ----------------- There was a problem\r\nNo username specified.\r\nServer not configured properly.\r\n\r\n\r\nThis is a detailed message\r\n"; Throwable t = new Throwable("This is a detailed message"); t.setStackTrace(new StackTraceElement[0]); assertThat("Message formatted without stacktrace fully present", Dialogs.getFormattedErrorMessageForPlainText(message, t), is(plainText)); }
protected static String getFormattedErrorMessageForPlainText(String message, Throwable throwable){ StringBuilder sb = new StringBuilder(); if(!Strings.isNullOrEmpty(message)){ sb.append(message).append("\r\n"); } while (throwable != null && !Strings.isNullOrEmpty(throwable.getMessage())) { sb.append("\r\n\r\n").append(throwable.getMessage()).append("\r\n"); if (throwable.getStackTrace().length > 0) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); throwable.printStackTrace(pw); sb.append(sw.toString()); } throwable = throwable.getCause(); } return sb.toString(); }
Dialogs { protected static String getFormattedErrorMessageForPlainText(String message, Throwable throwable){ StringBuilder sb = new StringBuilder(); if(!Strings.isNullOrEmpty(message)){ sb.append(message).append("\r\n"); } while (throwable != null && !Strings.isNullOrEmpty(throwable.getMessage())) { sb.append("\r\n\r\n").append(throwable.getMessage()).append("\r\n"); if (throwable.getStackTrace().length > 0) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); throwable.printStackTrace(pw); sb.append(sw.toString()); } throwable = throwable.getCause(); } return sb.toString(); } }
Dialogs { protected static String getFormattedErrorMessageForPlainText(String message, Throwable throwable){ StringBuilder sb = new StringBuilder(); if(!Strings.isNullOrEmpty(message)){ sb.append(message).append("\r\n"); } while (throwable != null && !Strings.isNullOrEmpty(throwable.getMessage())) { sb.append("\r\n\r\n").append(throwable.getMessage()).append("\r\n"); if (throwable.getStackTrace().length > 0) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); throwable.printStackTrace(pw); sb.append(sw.toString()); } throwable = throwable.getCause(); } return sb.toString(); }  }
Dialogs { protected static String getFormattedErrorMessageForPlainText(String message, Throwable throwable){ StringBuilder sb = new StringBuilder(); if(!Strings.isNullOrEmpty(message)){ sb.append(message).append("\r\n"); } while (throwable != null && !Strings.isNullOrEmpty(throwable.getMessage())) { sb.append("\r\n\r\n").append(throwable.getMessage()).append("\r\n"); if (throwable.getStackTrace().length > 0) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); throwable.printStackTrace(pw); sb.append(sw.toString()); } throwable = throwable.getCause(); } return sb.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 getFormattedErrorMessageForPlainText(String message, Throwable throwable){ StringBuilder sb = new StringBuilder(); if(!Strings.isNullOrEmpty(message)){ sb.append(message).append("\r\n"); } while (throwable != null && !Strings.isNullOrEmpty(throwable.getMessage())) { sb.append("\r\n\r\n").append(throwable.getMessage()).append("\r\n"); if (throwable.getStackTrace().length > 0) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); throwable.printStackTrace(pw); sb.append(sw.toString()); } throwable = throwable.getCause(); } return sb.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);  }