### Question:
RemoteOauth2Service implements Oauth2Service { @Override public URI getAuthorizationRequestUri(Map<String, String> headers, Parameters parameters) throws IOException { try { return new URI(this.oauth2Client.getAuthorizationUrl(headers, parameters.asMap()).getHref()); } catch (URISyntaxException e) { throw new IOException(e); } } RemoteOauth2Service(Oauth2Client oauth2Client); @Override URI getAuthorizationRequestUri(Map<String, String> headers, Parameters parameters); @Override TokenResponse getToken(Map<String, String> headers, Parameters parameters);  }### Answer:
@Test void getAuthorizationRequestUri() throws IOException { Oauth2Service.Parameters parameters = new Oauth2Service.Parameters(); String authUrl = "http: doReturn(buildHref(authUrl)).when(oauth2Client).getAuthorizationUrl(anyMap(), any()); URI uri = service.getAuthorizationRequestUri(new HashMap<>(), parameters); assertThat(uri).isEqualTo(URI.create(authUrl)); }
@Test void getAuthorizationRequestUriWithException() throws IOException { HashMap<String, String> headers = new HashMap<>(); Oauth2Service.Parameters parameters = new Oauth2Service.Parameters(); doReturn(buildHref("blablabla_unexisting_uri@2#^")) .when(oauth2Client) .getAuthorizationUrl(anyMap(), any()); assertThrows(IOException.class, () -> service.getAuthorizationRequestUri(headers, parameters)); }