### Question:
OidcConfigurationResolver { @Nullable public OidcConfiguration resolve() { if (!oidcEnabled) { LOGGER.debug("Will not resolve OIDC configuration: OIDC is disabled"); return null; } if (issuer == null) { LOGGER.error("Cannot resolve OIDC configuration: No issuer provided"); return null; } OidcConfiguration configuration = CacheManager.getInstance().get(OidcConfiguration.class, CONFIGURATION_CACHE_KEY); if (configuration != null) { LOGGER.debug("OIDC configuration loaded from cache"); return configuration; } LOGGER.debug("Loading OIDC configuration for issuer " + issuer); try { configuration = ClientBuilder.newClient().target(issuer) .path(OPENID_CONFIGURATION_PATH) .request(MediaType.APPLICATION_JSON) .get(OidcConfiguration.class); } catch (WebApplicationException | ProcessingException e) { LOGGER.error("Failed to load OIDC configuration from issuer " + issuer + ": " + e.getMessage()); return null; } LOGGER.debug("Storing OIDC configuration in cache"); CacheManager.getInstance().put(CONFIGURATION_CACHE_KEY, configuration); return configuration; } OidcConfigurationResolver(final boolean oidcEnabled, final String issuer); static OidcConfigurationResolver getInstance(); @Nullable OidcConfiguration resolve();  }### Answer:
@Test public void resolveShouldReturnNullWhenOidcIsNotEnabled() { assertThat(new OidcConfigurationResolver(false, wireMockRule.baseUrl()).resolve()).isNull(); }
@Test public void resolveShouldReturnNullWhenAuthorityIsNull() { assertThat(new OidcConfigurationResolver(true, null).resolve()).isNull(); }
@Test public void resolveShouldReturnNullWhenServerRespondsWithNon200StatusCode() { wireMockRule.stubFor(get(urlPathEqualTo(OidcConfigurationResolver.OPENID_CONFIGURATION_PATH)) .willReturn(aResponse() .withStatus(HttpStatus.SC_NOT_FOUND))); assertThat(new OidcConfigurationResolver(true, wireMockRule.baseUrl()).resolve()).isNull(); verify(getRequestedFor(urlPathEqualTo(OidcConfigurationResolver.OPENID_CONFIGURATION_PATH))); }
@Test public void resolveShouldReturnNullWhenServerRespondsWithInvalidJson() { wireMockRule.stubFor(get(urlPathEqualTo(OidcConfigurationResolver.OPENID_CONFIGURATION_PATH)) .willReturn(aResponse() .withStatus(HttpStatus.SC_OK) .withHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()) .withBody("<?xml version=\"1.0\" ?>"))); assertThat(new OidcConfigurationResolver(true, wireMockRule.baseUrl()).resolve()).isNull(); verify(getRequestedFor(urlPathEqualTo(OidcConfigurationResolver.OPENID_CONFIGURATION_PATH))); }
@Test public void resolveShouldReturnConfigurationAndStoreItInCache() { wireMockRule.stubFor(get(urlPathEqualTo(OidcConfigurationResolver.OPENID_CONFIGURATION_PATH)) .willReturn(aResponse() .withStatus(HttpStatus.SC_OK) .withHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType()) .withBody("" + "{\n" + " \"issuer\": \"https: " \"authorization_endpoint\": \"https: " \"token_endpoint\": \"https: " \"userinfo_endpoint\": \"https: " \"jwks_uri\": \"https: "}"))); final OidcConfiguration oidcConfiguration = new OidcConfigurationResolver(true, wireMockRule.baseUrl()).resolve(); assertThat(oidcConfiguration).isNotNull(); assertThat(oidcConfiguration.getIssuer()).isEqualTo("https: assertThat(oidcConfiguration.getAuthorizationEndpointUri()).isEqualTo("https: assertThat(oidcConfiguration.getTokenEndpointUri()).isEqualTo("https: assertThat(oidcConfiguration.getUserInfoEndpointUri()).isEqualTo("https: assertThat(oidcConfiguration.getJwksUri()).isEqualTo("https: assertThat(new OidcConfigurationResolver(true, wireMockRule.baseUrl()).resolve()).isEqualTo(oidcConfiguration); verify(1, getRequestedFor(urlPathEqualTo(OidcConfigurationResolver.OPENID_CONFIGURATION_PATH))); }