### Question:
Response { public static HttpResponse createResponse(HttpResponseStatus status, String message) { HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status); if (message != null) { ChannelBuffer buf = ChannelBuffers.copiedBuffer(message.getBytes(CharsetUtil.UTF_8)); response.setContent(buf); response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, buf.array().length); } else { response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 0); } response.headers().set(HttpHeaders.Names.CONTENT_TYPE, APPLICATION_JSON); response.headers().set(HttpHeaders.Names.CACHE_CONTROL, HttpHeaders.Values.NO_STORE); response.headers().set(HttpHeaders.Names.PRAGMA, HttpHeaders.Values.NO_CACHE); return response; }  static HttpResponse createBadRequestResponse(); static HttpResponse createBadRequestResponse(String message); static HttpResponse createNotFoundResponse(); static HttpResponse createOkResponse(String jsonString); static HttpResponse createOAuthExceptionResponse(OAuthException ex); static HttpResponse createUnauthorizedResponse(); static HttpResponse createResponse(HttpResponseStatus status, String message); static final String CANNOT_REGISTER_APP; static final String NAME_OR_SCOPE_OR_URI_IS_NULL; static final String SCOPE_NOT_EXIST; static final String INVALID_CLIENT_ID; static final String INVALID_CLIENT_CREDENTIALS; static final String RESPONSE_TYPE_NOT_SUPPORTED; static final String INVALID_REDIRECT_URI; static final String MANDATORY_PARAM_MISSING; static final String CANNOT_ISSUE_TOKEN; static final String INVALID_AUTH_CODE; static final String GRANT_TYPE_NOT_SUPPORTED; static final String INVALID_ACCESS_TOKEN; static final String INVALID_REFRESH_TOKEN; static final String INVALID_USERNAME_PASSWORD; static final String CANNOT_AUTHENTICATE_USER; static final String NOT_FOUND_CONTENT; static final String UNSUPPORTED_MEDIA_TYPE; static final String CANNOT_UPDATE_APP; static final String UPDATE_APP_MANDATORY_PARAM_MISSING; static final String ALREADY_REGISTERED_APP; static final String CLIENT_APP_NOT_EXIST; static final String SCOPE_NOK_MESSAGE; static final String CLIENT_APP_UPDATED; static final String CANNOT_LIST_CLIENT_APPS; static final String INVALID_JSON_ERROR; static final String ERROR_NOT_INTEGER; static final String APPLICATION_JSON; }### Answer:
@Test public void when_create_response_with_message_set_content_type() throws Exception { HttpResponse response = Response.createResponse(HttpResponseStatus.BAD_REQUEST, Response.ALREADY_REGISTERED_APP); assertEquals(response.headers().get(HttpHeaders.Names.CONTENT_TYPE), "application/json"); assertEquals(response.headers().get(HttpHeaders.Names.CONTENT_LENGTH), String.valueOf(Response.ALREADY_REGISTERED_APP.getBytes().length)); assertEquals(response.headers().get(HttpHeaders.Names.CACHE_CONTROL), HttpHeaders.Values.NO_STORE); assertEquals(response.headers().get(HttpHeaders.Names.PRAGMA), HttpHeaders.Values.NO_CACHE); }
@Test public void when_no_message_in_response_set_content_length_zero() throws Exception { HttpResponse response = Response.createResponse(HttpResponseStatus.OK, null); assertEquals(response.headers().get(HttpHeaders.Names.CONTENT_LENGTH), "0"); }