### Question:
BaseRestResource { private Response handleException(Exception ex) { if (ex instanceof ResourceNotFoundError) { LOGGER.warn("Resource not found: " + ex.getMessage() + "; unable to fulfill REST API request", ex); return Response.status(Status.NOT_FOUND).entity(ex.getMessage()).type("text/plain").build(); } else if (ex instanceof AuthzException) { LOGGER.warn("Authorization failed; unable to fulfill REST API request", ex); return Response.status(Status.UNAUTHORIZED).entity(ex.getMessage()).type("text/plain").build(); } else if (ex instanceof IllegalArgumentException) { LOGGER.warn("Bad request; unable to fulfill REST API request", ex); return Response.status(Status.BAD_REQUEST).entity(ex.getMessage()).type("text/plain").build(); } else if (ex instanceof ResourceLockedError) { LOGGER.warn("Lock exception; unable to fulfill REST API request", ex); return Response.status(Status.CONFLICT).entity(ex.getMessage()).type(MediaType.TEXT_PLAIN).build(); } else if (ex instanceof ObjectValidityException){ LOGGER.warn("Validation exception; unable to fulfill REST API request", ex); if (((ObjectValidityException) ex).getValidation() != null) { String errors = DefaultSerializer.objectValidationToXml(((ObjectValidityException) ex).getValidation()); return Response.status(Status.BAD_REQUEST).entity(errors).type(MediaType.TEXT_XML).build(); } else { return Response.status(Status.BAD_REQUEST).entity(ex.getMessage()).type(MediaType.TEXT_PLAIN).build(); } } else if (ex instanceof RangeNotSatisfiableException) { LOGGER.warn("Bad range request: " + ex.getMessage() + "; unable to fulfill REST API request", ex); return Response.status(RangeNotSatisfiableException.STATUS_CODE).entity(ex.getMessage()).type(MediaType.TEXT_PLAIN).build(); } else { LOGGER.error("Unexpected error fulfilling REST API request", ex); throw new WebApplicationException(ex); } } BaseRestResource(Server server);  static final String VALID_PID_PART; static final String FORM; static final String HTML; static final String XML; static final String ZIP; static final MediaType TEXT_HTML; static final MediaType TEXT_XML; static final MediaType APP_ZIP; }### Answer:
@Test public void testExceptionResponses() throws Exception { Response output = null; output = test.handleException(new ObjectNotFoundException("This is testing exception handling"), false); assertEquals(HttpStatus.SC_NOT_FOUND, output.getStatus()); output = test.handleException(new ObjectNotInLowlevelStorageException("This is testing exception handling"), false); assertEquals(HttpStatus.SC_NOT_FOUND, output.getStatus()); output = test.handleException(new DatastreamNotFoundException("This is testing exception handling"), false); assertEquals(HttpStatus.SC_NOT_FOUND, output.getStatus()); output = test.handleException(new ObjectLockedException("This is testing exception handling"), false); assertEquals(HttpStatus.SC_CONFLICT, output.getStatus()); output = test.handleException(new DatastreamLockedException("This is testing exception handling"), false); assertEquals(HttpStatus.SC_CONFLICT, output.getStatus()); output = test.handleException(new RangeNotSatisfiableException("This is testing exception handling"), false); assertEquals(HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE, output.getStatus()); }