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

  final RequestContext requestContext = mock(RequestContext.class);
  final Request request = Request.forUri("/", "GET");
  final AtomicReference<String> requestId = new AtomicReference<>();
  when(requestContext.request()).thenReturn(request);
  Response<Object> response = Middlewares.exceptionAndRequestIdHandler()
      .apply(rc -> {
        requestId.set(MDC.get("request-id"));
        final CompletableFuture<Response<Object>> failure = new CompletableFuture<>();
        LoggerFactory.getLogger(MiddlewaresTest.class).error("deadbeef");
        failure.completeExceptionally(new RuntimeException("fubar", new IOException("deadbeef")));
        return failure;
      })
      .invoke(requestContext)
      .toCompletableFuture().get(5, SECONDS);
  assertThat(response, hasStatus(withCode(Status.INTERNAL_SERVER_ERROR)));
  assertThat(response, hasStatus(withReasonPhrase(is(
      "Internal Server Error (Request ID: " + requestId.get() + "): RuntimeException: fubar: IOException: deadbeef"))));
  assertThat(response, hasHeader("X-Request-Id", is(requestId.get())));
  assertThat(requestId.get(), isValidUuid());
}