### Question:
ClientRegistration { public JsonValue getAccessToken(final Context context, final String code, final String callbackUri) throws OAuth2ErrorException { final Request request = createRequestForAccessToken(code, callbackUri); final Response response = httpRequestToAuthorizationServer(context, request); checkResponseStatus(response, false); 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 shouldGetAccessToken() throws Exception { final String code = "sampleAuthorizationCodeForTestOnly"; final String callbackUri = "shouldBeACallbackUri"; final ClientRegistration cr = buildClientRegistration(); final Response response = new Response(); response.setStatus(Status.OK); response.setEntity(json(object(field("access_token", "ae32f")))); when(handler.handle(eq(context), any(Request.class))).thenReturn(newResponsePromise(response)); cr.getAccessToken(context, code, callbackUri); verify(handler).handle(eq(context), captor.capture()); final Request request = captor.getValue(); assertThat(request.getMethod()).isEqualTo("POST"); assertThat(request.getUri().toASCIIString()).isEqualTo(SAMPLE_URI + TOKEN_ENDPOINT); assertThat(request.getEntity().getString()).contains("grant_type=authorization_code", "redirect_uri=" + callbackUri, "code=" + code); }
@Test(dataProvider = "errorResponseStatus", expectedExceptions = OAuth2ErrorException.class) public void shouldFailToGetAccessTokenWhenReceiveErrorResponse(final Status errorResponseStatus) throws Exception { final Response response = new Response(); response.setStatus(errorResponseStatus); response.setEntity(json(object(field("error", "Generated by tests")))); when(handler.handle(eq(context), any(Request.class))).thenReturn(newResponsePromise(response)); buildClientRegistration().getAccessToken(context, "code", "callbackUri"); }