### Question:
ClientRegistration { public JsonValue getUserInfo(final Context context, final OAuth2Session session) throws ResponseException, OAuth2ErrorException { final Request request = createRequestForUserInfo(session.getAccessToken()); final Response response = httpRequestToAuthorizationServer(context, request); if (!Status.OK.equals(response.getStatus())) { final OAuth2BearerWWWAuthenticateHeader header = OAuth2BearerWWWAuthenticateHeader.valueOf(response); final OAuth2Error error = header.getOAuth2Error(); final OAuth2Error bestEffort = OAuth2Error.bestEffortResourceServerError(response.getStatus(), error); throw new OAuth2ErrorException(bestEffort); } return getJsonContent(response); } ClientRegistration(final String name,
                              final JsonValue config,
                              final Issuer issuer,
                              final Handler registrationHandler); String getName(); JsonValue getAccessToken(final Context context,
                                    final String code,
                                    final String callbackUri); String getClientId(); Issuer getIssuer(); JsonValue refreshAccessToken(final Context context,
                                        final OAuth2Session session); List<String> getScopes(); JsonValue getUserInfo(final Context context,
                                 final OAuth2Session session); ClientRegistration setTokenEndpointUseBasicAuth(final boolean useBasicAuth);  }### Answer:
@Test public void shouldGetUserInfo() throws Exception { final ClientRegistration clientRegistration = buildClientRegistration(); Response response = new Response(); response.setStatus(Status.OK); response.setEntity(json(object(field("name", "bjensen")))); when(handler.handle(eq(context), any(Request.class))) .thenReturn(Promises.<Response, NeverThrowsException>newResultPromise(response)); clientRegistration.getUserInfo(context, session); verify(handler).handle(eq(context), captor.capture()); Request request = captor.getValue(); assertThat(request.getMethod()).isEqualTo("GET"); assertThat(request.getUri().toASCIIString()).isEqualTo(SAMPLE_URI + USER_INFO_ENDPOINT); assertThat(request.getHeaders().get("Authorization").getValues()).isNotEmpty(); }
@Test(expectedExceptions = OAuth2ErrorException.class, expectedExceptionsMessageRegExp = "error=\"server_error\"") public void shouldFailToGetUserInfoWhenReceiveErrorResponse() throws Exception { Response response = new Response(); response.setStatus(Status.TEAPOT); response.setEntity(setErrorEntity()); when(handler.handle(eq(context), any(Request.class))) .thenReturn(Promises.<Response, NeverThrowsException>newResultPromise(response)); buildClientRegistration().getUserInfo(context, session); }