### Question:
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);  }### Answer:
@Test public void testTruncateThrowable_lessThanMaxLength() { Throwable t = Mockito.mock(Throwable.class); String toString = "1234567890"; when(t.toString()).thenReturn(toString); assertEquals( "truncateThrowable should not truncate when length < maxLength", toString, loggerDelegate.truncateThrowable(t, 11)); }
@Test public void testTruncateThrowable_equalsMaxLength() { Throwable t = Mockito.mock(Throwable.class); String toString = "1234567890"; when(t.toString()).thenReturn(toString); assertEquals( "truncateThrowable should not truncate when length == maxLength", toString, loggerDelegate.truncateThrowable(t, 10)); }
@Test public void testTruncateThrowable_exceedsMaxLength() { Throwable t = Mockito.mock(Throwable.class); String toString = "1234567890"; when(t.toString()).thenReturn(toString); assertEquals( "truncateThrowable should truncate when length > maxLength", "123456...", loggerDelegate.truncateThrowable(t, 9)); }
@Test public void testTruncateThrowable_trimsNewLines() { Throwable t = Mockito.mock(Throwable.class); String toString = String.format("lineA%nlineB%nlineC%n"); when(t.toString()).thenReturn(toString); assertEquals( "truncateThrowable should remove all new lines", "lineAlineBlineC", loggerDelegate.truncateThrowable(t, 15)); }
@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)); }