### Question:
OpenAmAccessTokenResolver implements AccessTokenResolver { @Override public AccessToken resolve(Context context, final String token) throws OAuth2TokenException { try { Request request = new Request(); request.setMethod("GET"); request.setUri(new URI(tokenInfoEndpoint)); Form form = new Form(); form.add("access_token", token); form.toRequestQuery(request); Response response = null; try { response = blockingCall(client, context, request); } catch (InterruptedException e) { throw new OAuth2TokenException("AccessToken loading has been interrupted", e); } if (isResponseEmpty(response)) { throw new OAuth2TokenException("Authorization Server did not return any AccessToken"); } JsonValue content = asJson(response.getEntity()); if (isOk(response)) { return builder.build(content); } if (content.isDefined("error")) { String error = content.get("error").asString(); String description = content.get("error_description").asString(); throw new OAuth2TokenException(format("Authorization Server returned an error " + "(error: %s, description: %s)", error, description)); } throw new OAuth2TokenException("AccessToken returned by the AuthorizationServer has a problem"); } catch (URISyntaxException e) { throw new OAuth2TokenException( format("The token_info endpoint %s could not be accessed because it is a malformed URI", tokenInfoEndpoint), e); } } OpenAmAccessTokenResolver(final Handler client,
                                     final TimeService time,
                                     final String tokenInfoEndpoint);  OpenAmAccessTokenResolver(final Handler client,
                                     final OpenAmAccessToken.Builder builder,
                                     final String tokenInfoEndpoint); @Override AccessToken resolve(Context context, final String token);  }### Answer:
@Test public void shouldProduceAnAccessToken() throws Exception { when(time.now()).thenReturn(0L); Handler client = spy(new ResponseHandler(response(Status.OK, doubleQuote("{'expires_in':10, " + "'access_token':'ACCESS_TOKEN', " + "'scope': [ 'email', 'name' ]}")))); OpenAmAccessTokenResolver resolver = new OpenAmAccessTokenResolver(client, time, "/oauth2/tokeninfo"); final RootContext context = new RootContext(); AccessToken token = resolver.resolve(context, TOKEN); assertThat(token.getToken()).isEqualTo(TOKEN); assertThat(token.getExpiresAt()).isEqualTo(10000L); verify(client).handle(contextCaptor.capture(), any(Request.class)); assertThat(contextCaptor.getValue()).isSameAs(context); }
@Test(expectedExceptions = OAuth2TokenException.class) public void shouldThrowAnOAuthTokenExceptionCausedByAnError() throws Exception { Handler client = new ResponseHandler(response(Status.BAD_REQUEST, doubleQuote("{'error':'ERROR'}"))); OpenAmAccessTokenResolver resolver = new OpenAmAccessTokenResolver(client, time, "/oauth2/tokeninfo"); resolver.resolve(new RootContext(), TOKEN); }