### Question:
BaseOauth2Service implements Oauth2Service { @Override public TokenResponse getToken(Map<String, String> headers, Parameters parameters) throws IOException { Response<TokenResponse> response = httpClient.post(getTokenEndpoint(parameters)) .urlEncodedBody(parameters.asMap()) .send(jsonResponseHandler(TokenResponse.class)); return response.getBody(); } 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 getToken_withAvailableScaOauthLink() throws IOException { Mockito.doReturn(authorizationServerMetadata()) .when(httpClient).send(Mockito.argThat(req -> req.uri().equals(SCA_OAUTH_LINK)), Mockito.any()); Mockito.doReturn(tokenResponse()) .when(httpClient).send(Mockito.argThat(req -> req.uri().equals(TOKEN_ENDPOINT)), Mockito.any()); TokenResponse actual = oauth2Service.getToken(null, parameters); Mockito.verify(httpClient, Mockito.times(2)) .send(Mockito.any(), Mockito.any()); assertEquals(ACCESS_TOKEN, actual.getAccessToken()); }
@Test void getToken_withAvailableTokenEndpoint() throws IOException { parameters.setTokenEndpoint(TOKEN_ENDPOINT); Mockito.doReturn(tokenResponse()).when(httpClient).send(Mockito.any(), Mockito.any()); TokenResponse actual = oauth2Service.getToken(null, parameters); Mockito.verify(httpClient, Mockito.times(1)) .send(Mockito.any(), Mockito.any()); assertEquals(ACCESS_TOKEN, actual.getAccessToken()); }