SpringWebResource extends ResourceBase { protected ResponseEntity<?> handleExceptions(Supplier<ResponseEntity<?>> response) { return handleExceptions(response::get, this::toErrorResponse); }    }
@Test public void handleExceptionsReturnsResponseWhenSuccessful() { ResponseEntity<?> response = resource.handleExceptions(() -> ok("ok")); assertThat(response.getStatusCode(), is(OK)); assertThat(response.getBody(), is("ok")); }
@Test public void handleExceptionsReturnsResponseOnFailure() { ResponseEntity<?> response = resource.handleExceptions(() -> { throw new RuntimeException("error"); }); assertThat(response.getStatusCode(), is(INTERNAL_SERVER_ERROR)); assertThat(((ErrorResponse) response.getBody()).error, is("error")); }