LogbookHttpAsyncResponseConsumer extends ForwardingHttpAsyncResponseConsumer<T> { @Override public void responseCompleted(final HttpContext context) { final ResponseProcessingStage stage = find(context); try { stage.process(new RemoteResponse(response)).write(); } catch (final IOException e) { throw new UncheckedIOException(e); } delegate().responseCompleted(context); } LogbookHttpAsyncResponseConsumer(final HttpAsyncResponseConsumer<T> consumer); @Override void responseReceived(final HttpResponse response); @Override void responseCompleted(final HttpContext context);  }
@Test void shouldWrapIOException() throws IOException { final HttpAsyncResponseConsumer<HttpResponse> unit = new LogbookHttpAsyncResponseConsumer<>(createConsumer()); final BasicHttpContext context = new BasicHttpContext(); context.setAttribute(Attributes.STAGE, stage); final ResponseWritingStage last = mock(ResponseWritingStage.class); when(stage.process(any())).thenReturn(last); doThrow(new IOException()).when(last).write(); assertThrows(UncheckedIOException.class, () -> unit.responseCompleted(context)); }