### Question:
BaseOauth2Service implements Oauth2Service { @Override public URI getAuthorizationRequestUri(Map<String, String> headers, Parameters parameters) throws IOException { return UriBuilder.fromUri(getAuthorizationEndpoint(parameters)) .queryParam(Parameters.RESPONSE_TYPE, ResponseType.CODE.toString()) .queryParam(Parameters.STATE, parameters.getState()) .queryParam(Parameters.REDIRECT_URI, parameters.getRedirectUri()) .queryParam(Parameters.SCOPE, parameters.getScope()) .build(); } BaseOauth2Service(Aspsp aspsp, HttpClient httpClient); @Override URI getAuthorizationRequestUri(Map<String, String> headers, Parameters parameters); @Override TokenResponse getToken(Map<String, String> headers, Parameters parameters);  }### Answer:
@Test void scaOauthLinkUsedForAuthorizationServerMetadataResolution() throws IOException { Mockito.doReturn(authorizationServerMetadata()) .when(httpClient).send(Mockito.argThat(req -> req.uri().equals(SCA_OAUTH_LINK)), Mockito.any()); oauth2Service.getAuthorizationRequestUri(null, parameters); Mockito.verify(httpClient, Mockito.times(1)) .send(Mockito.argThat(req -> req.uri().equals(SCA_OAUTH_LINK)), Mockito.any()); }
@Test void authorizationServerMetadataResolutionFallsBackToIdpUrlWhenScaOauthLinkIsMissing() throws IOException { Mockito.doReturn(authorizationServerMetadata()) .when(httpClient).send(Mockito.argThat(req -> req.uri().equals(IDP_URL)), Mockito.any()); oauth2Service.getAuthorizationRequestUri(null, new Parameters()); Mockito.verify(httpClient, Mockito.times(1)) .send(Mockito.argThat(req -> req.uri().equals(IDP_URL)), Mockito.any()); }
@Test void getAuthorizationEndpoint_withAuthorisationEndpoint() throws IOException { parameters.setAuthorizationEndpoint(AUTHORISATION_ENDPOINT); parameters.setState(STATE); parameters.setRedirectUri(REDIRECT_URI); String expectedAuthorisationRequestUri = AUTHORISATION_ENDPOINT + "?" + Parameters.RESPONSE_TYPE + "=" + Oauth2Service.ResponseType.CODE.toString() + "&" + Parameters.STATE + "=" + STATE + "&" + Parameters.REDIRECT_URI + "=" + URLEncoder.encode(REDIRECT_URI, StandardCharsets.UTF_8.name()); URI actual = oauth2Service.getAuthorizationRequestUri(null, parameters); assertEquals(expectedAuthorisationRequestUri, actual.toString()); }