SearchExceptionMapper implements ExceptionMapper<SearchException> { public Response toResponse(final SearchException exception) { if (exception instanceof EmptyQueryException) { return ErrorResponseBuilder .from(new BadRequestException()) .build(); } return ErrorResponseBuilder .from(exception) .build(); }  Response toResponse(final SearchException exception);  }
@Test public void testToResponse() { SearchExceptionMapper mapper = new SearchExceptionMapper(); SearchException e = new SearchException("test"); Response r = mapper.toResponse(e); ErrorResponse er = (ErrorResponse) r.getEntity(); assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), r.getStatus()); assertEquals(Status.INTERNAL_SERVER_ERROR, er.getHttpStatus()); assertEquals("Internal Server Error", er.getErrorDescription()); }
@Test public void testEmptyQueryResponse() { SearchExceptionMapper mapper = new SearchExceptionMapper(); EmptyQueryException e = new EmptyQueryException(); Response r = mapper.toResponse(e); ErrorResponse er = (ErrorResponse) r.getEntity(); assertEquals(Status.BAD_REQUEST.getStatusCode(), r.getStatus()); assertEquals(Status.BAD_REQUEST, er.getHttpStatus()); assertEquals("HTTP 400 Bad Request", er.getErrorDescription()); }