@Test
public void doExtractAuthenticationWhenAuthorizationContextProviderErrors() {

    when(jwtValidator.validate(any(JsonWebToken.class)))
            .thenReturn(CompletableFuture.completedFuture(BinaryValidationResult.valid()));
    when(authenticationContextProvider.getAuthenticationResult(any(JsonWebToken.class), any(DittoHeaders.class)))
            .thenThrow(new RuntimeException("Something happened"));
    final RequestContext requestContext = mockRequestContext(VALID_AUTHORIZATION_HEADER);
    final AuthenticationResult authenticationResult = underTest.authenticate(requestContext, knownDittoHeaders);
    verify(authenticationContextProvider).getAuthenticationResult(any(JsonWebToken.class), any(DittoHeaders.class));
    softly.assertThat(authenticationResult.isSuccess()).isFalse();
    softly.assertThat(authenticationResult.getReasonOfFailure())
            .isExactlyInstanceOf(GatewayAuthenticationFailedException.class);
    final GatewayAuthenticationFailedException reasonOfFailure =
            (GatewayAuthenticationFailedException) authenticationResult.getReasonOfFailure();
    softly.assertThat(reasonOfFailure).hasMessage("The JWT could not be verified.");
    softly.assertThat(reasonOfFailure.getDescription()).contains("Something happened");
    softly.assertThat(reasonOfFailure.getDittoHeaders().getCorrelationId())
            .isEqualTo(knownDittoHeaders.getCorrelationId());
}