### Question:
OidcConfigurationServiceWithCache { @Nullable public OAuth2ServiceEndpointsProvider getOrRetrieveEndpoints(URI discoveryEndpointUri) throws OAuth2ServiceException { assertNotNull(discoveryEndpointUri, "discoveryEndpointUri must not be null."); String cacheKey = discoveryEndpointUri.toString(); OAuth2ServiceEndpointsProvider endpointsProvider = getCache().getIfPresent(cacheKey); if (endpointsProvider == null) { endpointsProvider = getOidcConfigurationService().retrieveEndpoints(discoveryEndpointUri); if (endpointsProvider == null) { return null; } getCache().put(cacheKey, endpointsProvider); } return getCache().getIfPresent(cacheKey); } private  OidcConfigurationServiceWithCache(); static OidcConfigurationServiceWithCache getInstance(); OidcConfigurationServiceWithCache withOidcConfigurationService(
			OidcConfigurationService oidcConfigurationService); OidcConfigurationServiceWithCache withCacheTime(int timeInSeconds); OidcConfigurationServiceWithCache withCacheSize(int size); @Nullable OAuth2ServiceEndpointsProvider getOrRetrieveEndpoints(URI discoveryEndpointUri); void clearCache();  }### Answer:
@Test public void retrieveEndpoints() throws OAuth2ServiceException, InvalidKeySpecException, NoSuchAlgorithmException { OAuth2ServiceEndpointsProvider endpointsProvider = cut.getOrRetrieveEndpoints(DISCOVERY_URI); Assertions.assertThat(endpointsProvider).isSameAs(oidcEndpointsProviderMock); Mockito.verify(oidcConfigServiceMock, times(1)) .retrieveEndpoints(DISCOVERY_URI); }
@Test public void getCachedEndpoints() throws OAuth2ServiceException { OAuth2ServiceEndpointsProvider endpointsProvider = cut.getOrRetrieveEndpoints(DISCOVERY_URI); OAuth2ServiceEndpointsProvider cachedEndpointsProvider = cut.getOrRetrieveEndpoints(DISCOVERY_URI); Assertions.assertThat(cachedEndpointsProvider).isNotNull(); Assertions.assertThat(cachedEndpointsProvider).isSameAs(endpointsProvider); Mockito.verify(oidcConfigServiceMock, times(1)) .retrieveEndpoints(DISCOVERY_URI); }
@Test public void requestFails_throwsException() throws OAuth2ServiceException { when(oidcConfigServiceMock.retrieveEndpoints(any())) .thenThrow(new OAuth2ServiceException("Currently unavailable")); assertThatThrownBy(() -> { cut.getOrRetrieveEndpoints(DISCOVERY_URI); }).isInstanceOf(OAuth2ServiceException.class).hasMessageStartingWith("Currently unavailable"); }
@Test public void retrieveEndpointsForAnotherIssuer() throws OAuth2ServiceException { cut.getOrRetrieveEndpoints(DISCOVERY_URI); cut.getOrRetrieveEndpoints(URI.create("http: Mockito.verify(oidcConfigServiceMock, times(2)) .retrieveEndpoints(any()); }