### Question:
DefaultOidcConfigurationService implements OidcConfigurationService { @Override public OAuth2ServiceEndpointsProvider retrieveEndpoints(@Nonnull URI discoveryEndpointUri) throws OAuth2ServiceException { Assertions.assertNotNull(discoveryEndpointUri, "discoveryEndpointUri must not be null!"); HttpUriRequest request = new HttpGet(discoveryEndpointUri); try (CloseableHttpResponse response = httpClient.execute(request)) { String bodyAsString = HttpClientUtil.extractResponseBodyAsString(response); int statusCode = response.getStatusLine().getStatusCode(); return handleResponse(bodyAsString, statusCode, discoveryEndpointUri); } catch (IOException e) { throw OAuth2ServiceException.builder("Error retrieving configured oidc endpoints: " + e.getMessage()) .withUri(discoveryEndpointUri) .build(); } } DefaultOidcConfigurationService();  DefaultOidcConfigurationService(CloseableHttpClient httpClient); static URI getDiscoveryEndpointUri(@Nonnull String issuerUri); @Override OAuth2ServiceEndpointsProvider retrieveEndpoints(@Nonnull URI discoveryEndpointUri);  }### Answer:
@Test public void retrieveEndpoints_parameterIsNull_throwsException() { assertThatThrownBy(() -> cut.retrieveEndpoints(null)) .isInstanceOf(IllegalArgumentException.class); }
@Test public void retrieveEndpoints_badRequest_throwsException() throws IOException { String errorDescription = "Something wen't wrong"; CloseableHttpResponse response = HttpClientTestFactory .createHttpResponse(errorDescription, HttpStatus.SC_BAD_REQUEST); when(httpClientMock.execute(any())).thenReturn(response); assertThatThrownBy(() -> retrieveEndpoints()) .isInstanceOf(OAuth2ServiceException.class) .hasMessageContaining(errorDescription); }
@Test public void retrieveEndpoints_executesHttpGetRequestWithCorrectURI() throws IOException { mockResponse(); retrieveEndpoints(); Mockito.verify(httpClientMock, times(1)).execute(argThat(isHttpGetAndContainsCorrectURI())); }
@Test public void retrieveEndpoints_errorOccurs_throwsServiceException() throws IOException { String errorMessage = "useful error message"; when(httpClientMock.execute(any())).thenThrow(new IOException(errorMessage)); assertThatThrownBy(() -> retrieveEndpoints()) .isInstanceOf(OAuth2ServiceException.class) .hasMessageContaining(errorMessage); }
@Test public void retrieveEndpoints_containsBothKeys() throws IOException { mockResponse(); OAuth2ServiceEndpointsProvider result = retrieveEndpoints(); assertThat(result.getTokenEndpoint().toString()).isEqualTo("http: assertThat(result.getJwksUri().toString()).isEqualTo("http: assertThat(result.getAuthorizeEndpoint().toString()).isEqualTo("http: }