@Test
public void verifyThatKeyIsNotCachedOnErrorResponseFromDiscoveryEndpoint() {

    mockErrorDiscoveryEndpointRequest();
    assertThatExceptionOfType(ExecutionException.class)
            .isThrownBy(() -> underTest.getPublicKey("google.com", KEY_ID).get(LATCH_TIMEOUT, TimeUnit.SECONDS))
            .withCauseExactlyInstanceOf(GatewayAuthenticationProviderUnavailableException.class);
    verify(httpClientMock).createSingleHttpRequest(DISCOVERY_ENDPOINT_REQUEST);
    verify(httpClientMock, never()).createSingleHttpRequest(PUBLIC_KEYS_REQUEST);
    Mockito.clearInvocations(httpClientMock);
    assertThatExceptionOfType(ExecutionException.class)
            .isThrownBy(() -> underTest.getPublicKey("google.com", KEY_ID).get(LATCH_TIMEOUT, TimeUnit.SECONDS))
            .withCauseExactlyInstanceOf(GatewayAuthenticationProviderUnavailableException.class);
    verify(httpClientMock).createSingleHttpRequest(DISCOVERY_ENDPOINT_REQUEST);
    verify(httpClientMock, never()).createSingleHttpRequest(PUBLIC_KEYS_REQUEST);
}