### Question:
TokenEndpointResource extends ServerResource { @Post public Representation token(Representation entity) throws OAuth2RestletException { final OAuth2Request request = requestFactory.create(getRequest()); try { final AccessToken accessToken = accessTokenService.requestAccessToken(request); for (TokenRequestHook hook : hooks) { hook.afterTokenHandling(request, getRequest(), getResponse()); } return jacksonRepresentationFactory.create(accessToken.toMap()); } catch (RedirectUriMismatchException e) { throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), request.<String>getParameter("state")); } catch (IllegalArgumentException e) { throw new OAuth2RestletException(400, "invalid_request", e.getMessage(), request.<String>getParameter("redirect_uri"), request.<String>getParameter("state")); } catch (InvalidClientAuthZHeaderException e) { getResponse().setChallengeRequests(singletonList( new ChallengeRequest( ChallengeScheme.valueOf(SUPPORTED_RESTLET_CHALLENGE_SCHEMES.get(e.getChallengeScheme())), e.getChallengeRealm()))); throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), request.<String>getParameter("state")); } catch (OAuth2Exception e) { throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), request.<String>getParameter("redirect_uri"), request.<String>getParameter("state")); } } @Inject  TokenEndpointResource(OAuth2RequestFactory<?, Request> requestFactory, AccessTokenService accessTokenService,
            ExceptionHandler exceptionHandler, Set<TokenRequestHook> hooks,
            JacksonRepresentationFactory jacksonRepresentationFactory); @Post Representation token(Representation entity);  }### Answer:
@Test public void testToken() throws Exception { Context context = new Context(); Request request = new Request(); Response response = new Response(request); tokenEndpointResource.init(context, request, response); doReturn(new AccessToken(null, OAUTH_ACCESS_TOKEN, null)) .when(accessTokenService).requestAccessToken(any(OAuth2Request.class)); tokenEndpointResource.token(new EmptyRepresentation()); verify(hook).afterTokenHandling(any(OAuth2Request.class), eq(request), eq(response)); }