### Question:
HttpResponseFactory { public static HttpResponse createUnauthorizedResponse(String message) { HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UNAUTHORIZED); response.headers().set(HttpHeaders.Names.CONTENT_TYPE, APPLICATION_JSON); String errorMessage = ConfigLoader.getLoadedGlobalErrors().get(HttpResponseStatus.UNAUTHORIZED.getCode()); if (errorMessage == null) { errorMessage = message; } ChannelBuffer buf = ChannelBuffers.copiedBuffer(errorMessage.getBytes(CharsetUtil.UTF_8)); response.setContent(buf); response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, buf.array().length); return response; }  static HttpResponse createISEResponse(); static HttpResponse createUnauthorizedResponse(String message); static HttpResponse createNotFoundResponse(); static HttpResponse createOKResponse(String message); static HttpResponse createResponse(HttpResponseStatus httpStatus, String message); static final String NOT_FOUND_CONTENT; static final String APPLICATION_JSON; }### Answer:
@Test public void when_unauthorized_response_set_header_and_body() throws Exception { mockNoGlobalErrors(); String errorMsg = "no access token"; HttpResponse response = HttpResponseFactory.createUnauthorizedResponse(errorMsg); assertEquals(response.getStatus(), HttpResponseStatus.UNAUTHORIZED); assertEquals(response.headers().get(HttpHeaders.CONTENT_TYPE), HttpResponseFactory.APPLICATION_JSON); String error = new String(response.getContent().array()); assertEquals(error, errorMsg); }
@Test public void when_create_unauthorized_response_and_global_error_401_exists_use_global_error() throws Exception { mockGlobalErrors(); String errorMsg = "no access token"; HttpResponse response = HttpResponseFactory.createUnauthorizedResponse(errorMsg); assertEquals(response.getStatus(), HttpResponseStatus.UNAUTHORIZED); assertEquals(response.headers().get(HttpHeaders.CONTENT_TYPE), HttpResponseFactory.APPLICATION_JSON); String error = new String(response.getContent().array()); assertEquals(error, customUnauthorizedResponse); }