@Test
public void testExceptionHandlerForAsyncException()
    throws InterruptedException, ExecutionException, TimeoutException {

  RequestContext requestContext = mock(RequestContext.class);
  Request request = Request.forUri("/", "GET");
  when(requestContext.request()).thenReturn(request);
  CompletableFuture<?> failedFuture = new CompletableFuture();
  failedFuture.completeExceptionally(new ResponseException(Response.forStatus(Status.IM_A_TEAPOT)));
  Response<Object> response = Middlewares.exceptionAndRequestIdHandler()
      .apply(mockInnerHandler(requestContext, failedFuture))
      .invoke(requestContext)
      .toCompletableFuture().get(5, SECONDS);
  assertThat(response, hasStatus(withCode(Status.IM_A_TEAPOT)));
}