### Question:
HttpRequestHandler extends SimpleChannelUpstreamHandler { protected HttpResponse handleTokenValidate(HttpRequest req) { HttpResponse response = null; QueryStringDecoder dec = new QueryStringDecoder(req.getUri()); Map<String, List<String>> params = dec.getParameters(); String tokenParam = QueryParameter.getFirstElement(params, QueryParameter.TOKEN); if (tokenParam == null || tokenParam.isEmpty()) { response = Response.createBadRequestResponse(); } else { AccessToken token = auth.isValidToken(tokenParam); if (token != null) { Gson gson = new Gson(); String json = gson.toJson(token); log.debug(json); response = Response.createOkResponse(json); } else { response = Response.createUnauthorizedResponse(); } } return response; }  @Override void messageReceived(ChannelHandlerContext ctx, MessageEvent e);  }### Answer:
@Test public void when_token_is_null_do_not_try_to_validate_it() throws Exception { String uri = HttpRequestHandler.ACCESS_TOKEN_VALIDATE_URI; HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri); AuthorizationServer auth = mock(AuthorizationServer.class); handler.auth = auth; HttpResponse response = handler.handleTokenValidate(req); verify(handler.auth, times(0)).isValidToken(anyString()); assertEquals(response.getStatus(), HttpResponseStatus.BAD_REQUEST); }
@Test public void when_token_is_empty_do_not_try_to_validate_it() throws Exception { String uri = HttpRequestHandler.ACCESS_TOKEN_VALIDATE_URI + "?token="; HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri); AuthorizationServer auth = mock(AuthorizationServer.class); handler.auth = auth; HttpResponse response = handler.handleTokenValidate(req); verify(handler.auth, times(0)).isValidToken(anyString()); assertEquals(response.getStatus(), HttpResponseStatus.BAD_REQUEST); }