// when
final Response response = exceptionMapper.toResponse(ex);
final String entity = (String) response.getEntity();
assertThat(entity, is(not(nullValue())));
final JsonRepresentation jsonRepr = JsonMapper.instance().read(entity, JsonRepresentation.class);
// then
assertThat((String) response.getMetadata().get("Warning").get(0), is("199 RestfulObjects foobar"));
assertThat(jsonRepr.getString("message"), is("barfoo"));
final JsonRepresentation causedByRepr = jsonRepr.getRepresentation("causedBy");
assertThat(causedByRepr, is(not(nullValue())));
assertThat(causedByRepr.getString("message"), is(cause.getMessage()));
}