### Question:
KsqlExceptionMapper implements ExceptionMapper<Throwable> { @Override public Response toResponse(Throwable exception) { if (exception instanceof KsqlRestException) { KsqlRestException restException = (KsqlRestException)exception; return restException.getResponse(); } if (exception instanceof WebApplicationException) { WebApplicationException webApplicationException = (WebApplicationException)exception; return Response .status( Response.Status.fromStatusCode( webApplicationException.getResponse().getStatus())) .type(MediaType.APPLICATION_JSON_TYPE) .entity( new KsqlErrorMessage( webApplicationException.getResponse().getStatus() * Errors.HTTP_TO_ERROR_CODE_MULTIPLIER, webApplicationException)) .build(); } return Response .status(Response.Status.INTERNAL_SERVER_ERROR) .type(MediaType.APPLICATION_JSON_TYPE) .entity(new KsqlErrorMessage(Errors.ERROR_CODE_SERVER_ERROR, exception)) .build(); }  @Override Response toResponse(Throwable exception);  }### Answer:
@Test public void shouldReturnEmbeddedResponseForKsqlRestException() { Response response = Response.status(400).build(); assertThat( exceptionMapper.toResponse(new KsqlRestException(response)), sameInstance(response)); }
@Test public void shouldReturnCorrectResponseForWebAppException() { WebApplicationException webApplicationException = new WebApplicationException("error msg", 403); Response response = exceptionMapper.toResponse(webApplicationException); assertThat(response.getEntity(), instanceOf(KsqlErrorMessage.class)); KsqlErrorMessage errorMessage = (KsqlErrorMessage)response.getEntity(); assertThat(errorMessage.getMessage(), equalTo("error msg")); assertThat(errorMessage.getErrorCode(), equalTo(40300)); assertThat(response.getStatus(), equalTo(403)); }
@Test public void shouldReturnCorrectResponseForUnspecificException() { Response response = exceptionMapper.toResponse(new Exception("error msg")); assertThat(response.getEntity(), instanceOf(KsqlErrorMessage.class)); KsqlErrorMessage errorMessage = (KsqlErrorMessage)response.getEntity(); assertThat(errorMessage.getMessage(), equalTo("error msg")); assertThat(errorMessage.getErrorCode(), equalTo(Errors.ERROR_CODE_SERVER_ERROR)); assertThat(response.getStatus(), equalTo(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())); }