### Question:
AdorsysIntegOauth2Service implements Oauth2Service { @Override public URI getAuthorizationRequestUri(Map<String, String> headers, Parameters parameters) { requireValid(validateGetAuthorizationRequestUri(headers, parameters)); String scaOAuthUrl = getScaOAuthUrl(parameters); String authorisationUri = oauth2Api.getAuthorisationUri(scaOAuthUrl); authorisationUri = StringUri.appendQueryParam( authorisationUri, "redirect_uri", parameters.getRedirectUri() ); return URI.create(authorisationUri); } AdorsysIntegOauth2Service(Aspsp aspsp,
                                     HttpClient httpClient,
                                     Oauth2Api oauth2Api); @Override URI getAuthorizationRequestUri(Map<String, String> headers, Parameters parameters); @Override List<ValidationError> validateGetAuthorizationRequestUri(Map<String, String> headers,
                                                                    Parameters parameters); @Override TokenResponse getToken(Map<String, String> headers, Parameters parameters); @Override List<ValidationError> validateGetToken(Map<String, String> headers, Parameters parameters);  }### Answer:
@Test void getAuthorizationRequestUri_Failure_ScaOauthUrlIsNotProvided() { Parameters parameters = new Parameters(new HashMap<>()); when(aspsp.getIdpUrl()).thenReturn(null); Assertions.assertThrows( RequestValidationException.class, () -> { oauth2Service.getAuthorizationRequestUri(null, parameters); } ); }
@Test void getAuthorizationRequestUri_Failure_ScaOauthUrlIsEmptyParam() { Parameters parameters = new Parameters(new HashMap<>()); parameters.setScaOAuthLink(" "); when(aspsp.getIdpUrl()).thenReturn(null); Assertions.assertThrows( RequestValidationException.class, () -> oauth2Service.getAuthorizationRequestUri(null, parameters) ); }
@Test void getAuthorizationRequestUri_Failure_ScaOauthUrlIsEmpty() { Parameters parameters = new Parameters(new HashMap<>()); when(aspsp.getIdpUrl()).thenReturn(" "); Assertions.assertThrows( RequestValidationException.class, () -> oauth2Service.getAuthorizationRequestUri(null, parameters) ); }
@Test void getAuthorizationRequestUri_Success() { Parameters parameters = new Parameters(new HashMap<>()); parameters.setRedirectUri(REDIRECT_URI); when(aspsp.getIdpUrl()).thenReturn(IDP_URL); when(oauth2Api.getAuthorisationUri(IDP_URL)).thenReturn(AUTH_URL); URI actual = oauth2Service.getAuthorizationRequestUri(null, parameters); assertThat(actual).isEqualTo(AUTH_REQUEST_URI); }