ResourceException extends RuntimeException { public static String symbolForCode(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 INTERNAL_SERVER_ERROR: return "INTERNAL_SERVER_ERROR"; case NOT_IMPLEMENTED: return "NOT_IMPLEMENTED"; case UNSUPPORTED_MEDIA_TYPE: return "UNSUPPORTED_MEDIA_TYPE"; case SERVICE_UNAVAILABLE: return "SERVICE_UNAVAILABLE"; } return null; } ResourceException(int code);  ResourceException(int code, Object data); static int codeForSymbol(String sym); static String symbolForCode(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 INTERNAL_SERVER_ERROR; final static int NOT_IMPLEMENTED; final static int SERVICE_UNAVAILABLE; }
@Test public void testSymbolForCode() { assertEquals(ResourceException.symbolForCode(200), "OK"); assertEquals(ResourceException.symbolForCode(201), "CREATED"); assertEquals(ResourceException.symbolForCode(202), "ACCEPTED"); assertEquals(ResourceException.symbolForCode(204), "NO_CONTENT"); assertEquals(ResourceException.symbolForCode(301), "MOVED_PERMANENTLY"); assertEquals(ResourceException.symbolForCode(302), "FOUND"); assertEquals(ResourceException.symbolForCode(303), "SEE_OTHER"); assertEquals(ResourceException.symbolForCode(304), "NOT_MODIFIED"); assertEquals(ResourceException.symbolForCode(307), "TEMPORARY_REDIRECT"); assertEquals(ResourceException.symbolForCode(400), "BAD_REQUEST"); assertEquals(ResourceException.symbolForCode(403), "FORBIDDEN"); assertEquals(ResourceException.symbolForCode(401), "UNAUTHORIZED"); assertEquals(ResourceException.symbolForCode(404), "NOT_FOUND"); assertEquals(ResourceException.symbolForCode(409), "CONFLICT"); assertEquals(ResourceException.symbolForCode(410), "GONE"); assertEquals(ResourceException.symbolForCode(412), "PRECONDITION_FAILED"); assertEquals(ResourceException.symbolForCode(415), "UNSUPPORTED_MEDIA_TYPE"); assertEquals(ResourceException.symbolForCode(500), "INTERNAL_SERVER_ERROR"); assertEquals(ResourceException.symbolForCode(501), "NOT_IMPLEMENTED"); assertEquals(ResourceException.symbolForCode(503), "SERVICE_UNAVAILABLE"); assertEquals(ResourceException.symbolForCode(401), "UNAUTHORIZED"); assertNull(ResourceException.symbolForCode(1111)); }