StackTraceExpander { @VisibleForTesting @Nullable static String getCauseLine(@NotNull String line) { Matcher matcher = CAUSED_BY_LINE_PATTERN.matcher(line); return matcher.matches() ? matcher.group(1) : null; } StackTraceExpander(@NotNull String stackTraceLinePrefix, @NotNull String stackTraceCauseLinePrefix); void reset(); static boolean wasLineExpanded(@NotNull String line); @NotNull List<String> process(@NotNull String line);  }
@Test public void testCausedByMatcher() { String[] validCauses = new String[] { "Caused by: java.lang.RuntimeException", " Caused by: java.io.IOException", "\tCaused by: java.lang.IllegalArgumentException" }; for (String cause: validCauses) { assertThat(StackTraceExpander.getCauseLine(cause)).isEqualTo(cause.trim()); } String[] invalidCauses = new String[] { "at com.example.t1.MainActivity.one(MainActivity.java:31)", "... 15 more" }; for (String cause: invalidCauses) { Assert.assertNull(StackTraceExpander.getCauseLine(cause)); } }