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

  final RequestContext requestContext = mock(RequestContext.class);
  final String requestId = UUID.randomUUID().toString();
  final Request request = Request.forUri("/", "GET")
      .withHeader("X-Request-Id", requestId);
  final AtomicReference<String> propagatedRequestId = new AtomicReference<>();
  when(requestContext.request()).thenReturn(request);
  Response<Object> response = Middlewares.exceptionAndRequestIdHandler()
      .apply(rc -> {
        propagatedRequestId.set(MDC.get("request-id"));
        LoggerFactory.getLogger(MiddlewaresTest.class).info("I'm OK!");
        return completedFuture(Response.forStatus(Status.OK));
      })
      .invoke(requestContext)
      .toCompletableFuture().get(5, SECONDS);
  assertThat(response, hasStatus(withCode(Status.OK)));
  assertThat(response, hasHeader("X-Request-Id", is(requestId)));
  assertThat(propagatedRequestId.get(), is(requestId));
}