@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, // Use maxLength > length of 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, // Use maxLength == length of toString loggerDelegate.truncateThrowable(t, 10)); }
@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)); } }
@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...", // Use maxLength < length of toString loggerDelegate.truncateThrowable(t, 9)); }
Throwable throwable = remoteCallReturn.getException(); logArgs[8] = throwable != null; logArgs[9] = truncateThrowable(throwable, MAX_SUMMARY_ERROR_LENGTH);
Throwable throwable = remoteCallReturn.getException(); logArgs[8] = throwable != null; logArgs[9] = truncateThrowable(throwable, MAX_SUMMARY_ERROR_LENGTH);