StackTraceFormatter extends AbstractPluginableElement implements MessageFormatter { @Override public String format(String message) { StringBuilder sb = new StringBuilder(message.length()); final Iterable<String> split = Splitter.on("\n").split(message); for (String line : split) { sb.append(line.replaceFirst("\\s+at", " at")); if (STACK_TRACE_PATTERN.matcher(line).find()) { addCodeToLine(sb, line); } sb.append("\n"); } return sb.toString().trim(); } StackTraceFormatter(JumpToCodeService jumpToCodeService); @Override int getApiVersion(); @Override boolean formattingNeeded(String message); @Override String format(String message);  }
@Test public void testFormat() throws Exception { final JumpToCodeService mock = Mockito.mock(JumpToCodeService.class); Mockito.when(mock.getContentOptional(Mockito.any(LocationInfo.class))).thenAnswer(invocation -> { LocationInfo li = (LocationInfo) invocation.getArguments()[0]; return li.getLineNumber().map(l->l + ": code"); }); final StackTraceFormatter formatter = new StackTraceFormatter(mock); String message = "java.util.concurrent.ExecutionException: java.io.IOException: Error executing request, connection broken.... :)\n" + "\tat java.util.concurrent.FutureTask.report(FutureTask.java:122)\n" + "\tat test.sampleapp.SampleAppMultiThreadedFix2.lambda$performRequests$16(SampleAppMultiThreadedFix2.java:36)\n" + "\tat test.sampleapp.SampleAppMultiThreadedFix2$$Lambda$16/2016207428.accept(Unknown Source)\n" + "Caused by: java.io.IOException: Error executing request, connection broken.... :)\n" + "\tat test.sampleapp.services.hotels.HotelsService.getHotels(HotelsService.java:30)\n" + "\tat test.sampleapp.SampleAppMultiThreadedFix2$$Lambda$9/1549863774.call(Unknown Source)\n" + "\tat test.sampleapp.executors.MdcCallableWrapper.call(MdcCallableWrapper.java:32)\n" + "\t... 4 more"; final String format = formatter.format(message); String expected = "java.util.concurrent.ExecutionException: java.io.IOException: Error executing request, connection broken.... :)\n" + " at java.util.concurrent.FutureTask.report(FutureTask.java:122)\t " at test.sampleapp.SampleAppMultiThreadedFix2.lambda$performRequests$16(SampleAppMultiThreadedFix2.java:36)\t " at test.sampleapp.SampleAppMultiThreadedFix2$$Lambda$16/2016207428.accept(Unknown Source)\n" + "Caused by: java.io.IOException: Error executing request, connection broken.... :)\n" + " at test.sampleapp.services.hotels.HotelsService.getHotels(HotelsService.java:30)\t " at test.sampleapp.SampleAppMultiThreadedFix2$$Lambda$9/1549863774.call(Unknown Source)\n" + " at test.sampleapp.executors.MdcCallableWrapper.call(MdcCallableWrapper.java:32)\t "\t... 4 more"; Assert.assertEquals(format, expected); }