@Test public void testTruncateThrowable_ignoresNewLinesWhenTrimming() { Throwable t = Mockito.mock(Throwable.class); String toString = String.format("123%n456%n789%n0"); when(t.toString()).thenReturn(toString); assertEquals( "truncateThrowable should ignore new lines when trimming", "123456...", loggerDelegate.truncateThrowable(t, 9)); }
@VisibleForTesting CharSequence truncateThrowable(Throwable throwable, int maxLength) { if (throwable == null) { return null; } String truncated = NEWLINE_PATTERN.matcher(throwable.toString()).replaceAll(""); if (truncated.length() <= maxLength) { return truncated; } return new StringBuilder(maxLength) .append(truncated.substring(0, maxLength - ELLIPSIS.length())) .append(ELLIPSIS) .toString(); }
RemoteCallLoggerDelegate { @VisibleForTesting CharSequence truncateThrowable(Throwable throwable, int maxLength) { if (throwable == null) { return null; } String truncated = NEWLINE_PATTERN.matcher(throwable.toString()).replaceAll(""); if (truncated.length() <= maxLength) { return truncated; } return new StringBuilder(maxLength) .append(truncated.substring(0, maxLength - ELLIPSIS.length())) .append(ELLIPSIS) .toString(); } }
RemoteCallLoggerDelegate { @VisibleForTesting CharSequence truncateThrowable(Throwable throwable, int maxLength) { if (throwable == null) { return null; } String truncated = NEWLINE_PATTERN.matcher(throwable.toString()).replaceAll(""); if (truncated.length() <= maxLength) { return truncated; } return new StringBuilder(maxLength) .append(truncated.substring(0, maxLength - ELLIPSIS.length())) .append(ELLIPSIS) .toString(); } RemoteCallLoggerDelegate(
      Logger summaryLogger,
      Logger detailLogger,
      @Nullable PrettyPrinterInterface prettyPrinter,
      RemoteCallType remoteCallType); }
RemoteCallLoggerDelegate { @VisibleForTesting CharSequence truncateThrowable(Throwable throwable, int maxLength) { if (throwable == null) { return null; } String truncated = NEWLINE_PATTERN.matcher(throwable.toString()).replaceAll(""); if (truncated.length() <= maxLength) { return truncated; } return new StringBuilder(maxLength) .append(truncated.substring(0, maxLength - ELLIPSIS.length())) .append(ELLIPSIS) .toString(); } RemoteCallLoggerDelegate(
      Logger summaryLogger,
      Logger detailLogger,
      @Nullable PrettyPrinterInterface prettyPrinter,
      RemoteCallType remoteCallType); boolean isSummaryLoggable(boolean isSuccess); boolean isDetailsLoggable(boolean isSuccess); void logRequestDetails(RemoteCallReturn remoteCallReturn); void logRequestSummary(RemoteCallReturn remoteCallReturn); }
RemoteCallLoggerDelegate { @VisibleForTesting CharSequence truncateThrowable(Throwable throwable, int maxLength) { if (throwable == null) { return null; } String truncated = NEWLINE_PATTERN.matcher(throwable.toString()).replaceAll(""); if (truncated.length() <= maxLength) { return truncated; } return new StringBuilder(maxLength) .append(truncated.substring(0, maxLength - ELLIPSIS.length())) .append(ELLIPSIS) .toString(); } RemoteCallLoggerDelegate(
      Logger summaryLogger,
      Logger detailLogger,
      @Nullable PrettyPrinterInterface prettyPrinter,
      RemoteCallType remoteCallType); boolean isSummaryLoggable(boolean isSuccess); boolean isDetailsLoggable(boolean isSuccess); void logRequestDetails(RemoteCallReturn remoteCallReturn); void logRequestSummary(RemoteCallReturn remoteCallReturn);  }