ResourceException extends RuntimeException { public static String codeToString(int code) { switch (code) { case OK: return "OK"; case CREATED: return "Created"; case ACCEPTED: return "Accepted"; case NO_CONTENT: return "No Content"; case MOVED_PERMANENTLY: return "Moved Permanently"; case FOUND: return "Found"; case SEE_OTHER: return "See Other"; case NOT_MODIFIED: return "Not Modified"; case TEMPORARY_REDIRECT: return "Temporary Redirect"; case BAD_REQUEST: return "Bad Request"; case UNAUTHORIZED: return "Unauthorized"; case FORBIDDEN: return "Forbidden"; case NOT_FOUND: return "Not Found"; case CONFLICT: return "Conflict"; case GONE: return "Gone"; case PRECONDITION_FAILED: return "Precondition Failed"; case UNSUPPORTED_MEDIA_TYPE: return "Unsupported Media Type"; case PRECONDITION_REQUIRED: return "Precondition Required"; case TOO_MANY_REQUESTS: return "Too Many Requests"; case REQUEST_HEADER_FIELDS_TOO_LARGE: return "Request Header Fields Too Large"; case INTERNAL_SERVER_ERROR: return "Internal Server Error"; case NOT_IMPLEMENTED: return "Not Implemented"; case SERVICE_UNAVAILABLE: return "Service Unavailable"; case GATEWAY_TIMEOUT: return "Gateway Timeout"; case NETWORK_AUTHENTICATION_REQUIRED: return "Network Authentication Required"; default: return "" + code; } } ResourceException(int code);  ResourceException(int code, Object data); static String codeToString(int code); int getCode(); Object getData(); T getData(Class<T> cl); final static int OK; final static int CREATED; final static int ACCEPTED; final static int NO_CONTENT; final static int MOVED_PERMANENTLY; final static int FOUND; final static int SEE_OTHER; final static int NOT_MODIFIED; final static int TEMPORARY_REDIRECT; final static int BAD_REQUEST; final static int UNAUTHORIZED; final static int FORBIDDEN; final static int NOT_FOUND; final static int CONFLICT; final static int GONE; final static int PRECONDITION_FAILED; final static int UNSUPPORTED_MEDIA_TYPE; final static int PRECONDITION_REQUIRED; final static int TOO_MANY_REQUESTS; final static int REQUEST_HEADER_FIELDS_TOO_LARGE; final static int INTERNAL_SERVER_ERROR; final static int NOT_IMPLEMENTED; final static int SERVICE_UNAVAILABLE; final static int GATEWAY_TIMEOUT; final static int NETWORK_AUTHENTICATION_REQUIRED; }
@Test public void testCodeToString() { assertEquals("OK", ResourceException.codeToString(200)); assertEquals("Created", ResourceException.codeToString(201)); assertEquals("Accepted", ResourceException.codeToString(202)); assertEquals("No Content", ResourceException.codeToString(204)); assertEquals("Moved Permanently", ResourceException.codeToString(301)); assertEquals("Found", ResourceException.codeToString(302)); assertEquals("See Other", ResourceException.codeToString(303)); assertEquals("Not Modified", ResourceException.codeToString(304)); assertEquals("Temporary Redirect", ResourceException.codeToString(307)); assertEquals("Bad Request", ResourceException.codeToString(400)); assertEquals("Unauthorized", ResourceException.codeToString(401)); assertEquals("Forbidden", ResourceException.codeToString(403)); assertEquals("Not Found", ResourceException.codeToString(404)); assertEquals("Conflict", ResourceException.codeToString(409)); assertEquals("Gone", ResourceException.codeToString(410)); assertEquals("Precondition Failed", ResourceException.codeToString(412)); assertEquals("Unsupported Media Type", ResourceException.codeToString(415)); assertEquals("Precondition Required", ResourceException.codeToString(428)); assertEquals("Too Many Requests", ResourceException.codeToString(429)); assertEquals("Request Header Fields Too Large", ResourceException.codeToString(431)); assertEquals("Internal Server Error", ResourceException.codeToString(500)); assertEquals("Not Implemented", ResourceException.codeToString(501)); assertEquals("Service Unavailable", ResourceException.codeToString(503)); assertEquals("Gateway Timeout", ResourceException.codeToString(504)); assertEquals("Network Authentication Required", ResourceException.codeToString(511)); assertEquals("1001", ResourceException.codeToString(1001)); }