### Question:
HttpRequestHandler extends SimpleChannelUpstreamHandler { protected HttpResponse handleTokenRevoke(HttpRequest req) { boolean revoked = false; try { revoked = auth.revokeToken(req); } catch (OAuthException e) { log.error("cannot revoke token", e); invokeExceptionHandler(e, req); return Response.createOAuthExceptionResponse(e); } JsonObject json = new JsonObject(); json.addProperty("revoked", revoked); HttpResponse response = Response.createOkResponse(json.toString()); return response; }  @Override void messageReceived(ChannelHandlerContext ctx, MessageEvent e);  }### Answer:
@Test public void when_revoke_token_return_revoked_true_message() throws Exception { HttpRequest req = mock(HttpRequest.class); AuthorizationServer auth = mock(AuthorizationServer.class); willReturn(true).given(auth).revokeToken(req); handler.auth = auth; HttpResponse response = handler.handleTokenRevoke(req); assertEquals(response.getContent().toString(CharsetUtil.UTF_8), "{\"revoked\":true}"); }
@Test public void when_revoke_token_return_revoked_false_message() throws Exception { HttpRequest req = mock(HttpRequest.class); AuthorizationServer auth = mock(AuthorizationServer.class); willReturn(false).given(auth).revokeToken(req); handler.auth = auth; HttpResponse response = handler.handleTokenRevoke(req); assertEquals(response.getContent().toString(CharsetUtil.UTF_8), "{\"revoked\":false}"); }
@Test public void when_revoke_token_throws_exception_return_bad_request_message() throws Exception { HttpRequest req = mock(HttpRequest.class); OAuthException.log = mock(Logger.class); AuthorizationServer auth = mock(AuthorizationServer.class); String errorMsg = "something wrong"; willThrow(new OAuthException(errorMsg, HttpResponseStatus.BAD_REQUEST)) .given(auth).revokeToken(req); handler.auth = auth; HttpResponse response = handler.handleTokenRevoke(req); assertEquals(response.getContent().toString(CharsetUtil.UTF_8), errorMsg); assertEquals(response.getStatus(), HttpResponseStatus.BAD_REQUEST); }
@Test public void when_revoke_token_and_oauth_exception_return_error_response() throws Exception { HttpRequest req = mock(HttpRequest.class); AuthorizationServer auth = mock(AuthorizationServer.class); handler.auth = auth; willThrow(new OAuthException(Response.INVALID_CLIENT_CREDENTIALS, HttpResponseStatus.BAD_REQUEST)) .given(handler.auth).revokeToken(req); HttpResponse response = handler.handleTokenRevoke(req); assertEquals(response.getContent().toString(CharsetUtil.UTF_8), Response.INVALID_CLIENT_CREDENTIALS); assertEquals(response.getStatus(), HttpResponseStatus.BAD_REQUEST); }