### Question:
PkceOauth2Service implements Oauth2Service, PkceOauth2Extension { @Override public URI getAuthorizationRequestUri(Map<String, String> headers, Parameters parameters) throws IOException { return UriBuilder.fromUri(oauth2Service.getAuthorizationRequestUri(headers, parameters)) .queryParam(Parameters.CODE_CHALLENGE_METHOD, orElse(parameters.getCodeChallengeMethod(), "S256")) .queryParam(Parameters.CODE_CHALLENGE, orElse(parameters.getCodeChallenge(), this.codeChallenge())) .build(); } PkceOauth2Service(Oauth2Service oauth2Service); @Override URI getAuthorizationRequestUri(Map<String, String> headers, Parameters parameters); @Override TokenResponse getToken(Map<String, String> headers, Parameters parameters);  }### Answer:
@Test void getAuthorizationRequestUri() throws IOException { String authorisationRequestUri = "https: "response_type=code&state=state&redirect_uri=https%3A%2F%2Fredirect.uri"; String expectedOutput = authorisationRequestUri + "&" + Parameters.CODE_CHALLENGE_METHOD + "=S256&" + Parameters.CODE_CHALLENGE + "=" + pkceOauth2Service.codeChallenge(); Mockito.when(oauth2Service.getAuthorizationRequestUri(Mockito.any(), Mockito.any())) .thenReturn(URI.create(authorisationRequestUri)); URI actual = pkceOauth2Service.getAuthorizationRequestUri(null, parameters); Mockito.verify(oauth2Service, Mockito.times(1)) .getAuthorizationRequestUri(Mockito.any(), Mockito.any()); Assertions.assertEquals(actual.toString(), expectedOutput); }
@Test void getAuthorizationRequestUriWithOverriddenPkceParameters() throws IOException { String authorisationRequestUri = "https: "response_type=code&state=state&redirect_uri=https%3A%2F%2Fredirect.uri"; String codeChallengeMethod = "plain"; String codeChallenge = "code-challenge"; String expectedOutput = authorisationRequestUri + "&" + Parameters.CODE_CHALLENGE_METHOD + "=" + codeChallengeMethod + "&" + Parameters.CODE_CHALLENGE + "=" + codeChallenge; parameters.setCodeChallengeMethod(codeChallengeMethod); parameters.setCodeChallenge(codeChallenge); Mockito.when(oauth2Service.getAuthorizationRequestUri(Mockito.any(), Mockito.any())) .thenReturn(URI.create(authorisationRequestUri)); URI actual = pkceOauth2Service.getAuthorizationRequestUri(null, parameters); Mockito.verify(oauth2Service, Mockito.times(1)) .getAuthorizationRequestUri(Mockito.any(), Mockito.any()); Assertions.assertEquals(actual.toString(), expectedOutput); }