### Question:
PkceOauth2Service implements Oauth2Service, PkceOauth2Extension { @Override public TokenResponse getToken(Map<String, String> headers, Parameters parameters) throws IOException { if (GrantType.AUTHORIZATION_CODE.toString().equals(parameters.getGrantType())) { parameters.setCodeVerifier(orElse(parameters.getCodeVerifier(), this.codeVerifier())); } return oauth2Service.getToken(headers, parameters); } PkceOauth2Service(Oauth2Service oauth2Service); @Override URI getAuthorizationRequestUri(Map<String, String> headers, Parameters parameters); @Override TokenResponse getToken(Map<String, String> headers, Parameters parameters);  }### Answer:
@Test void codeVerifierParameterAddedForAuthorizationCodeExchange() throws IOException { parameters.setGrantType(GrantType.AUTHORIZATION_CODE.toString()); pkceOauth2Service.getToken(null, parameters); Mockito.verify(oauth2Service, Mockito.times(1)) .getToken(Mockito.any(), Mockito.argThat(p -> p.getCodeVerifier() != null && p.getCodeVerifier().equals(pkceOauth2Service.codeVerifier()))); }
@Test void codeVerifierParameterCanBeOverridden() throws IOException { parameters.setGrantType(GrantType.AUTHORIZATION_CODE.toString()); String codeVerifier = "code-verifier"; parameters.setCodeVerifier(codeVerifier); pkceOauth2Service.getToken(null, parameters); Mockito.verify(oauth2Service, Mockito.times(1)) .getToken(Mockito.any(), Mockito.argThat(p -> p.getCodeVerifier() != null && p.getCodeVerifier().equals(codeVerifier))); }
@Test void codeVerifierParameterIsNotAddedForTokenRefresh() throws IOException { parameters.setGrantType(GrantType.REFRESH_TOKEN.toString()); pkceOauth2Service.getToken(null, parameters); Mockito.verify(oauth2Service, Mockito.times(1)) .getToken(Mockito.any(), Mockito.argThat(p -> p.getCodeVerifier() == null)); }