@Test public void itShouldMapRuntimeExceptionCausedByDomainServiceException() { DomainServiceException domainServiceException = mock(DomainServiceException.class); RuntimeException runtimeException = new RuntimeException(domainServiceException); Response expected = mock(Response.class); when(domainServiceExceptionMapper.toResponse(domainServiceException)).thenReturn(expected); Response actual = mapper.toResponse(runtimeException); verify(domainServiceExceptionMapper).toResponse(domainServiceException); assertThat(actual).isSameAs(expected); }
@Override public Response toResponse(RuntimeException exception) { Throwable cause = exception.getCause(); if (cause instanceof DomainServiceException) { return domainServiceExceptionMapper.toResponse((DomainServiceException) cause); } int status = HttpStatus.INTERNAL_SERVER_ERROR_500; return Response.status(status) .type(MediaType.APPLICATION_JSON) .entity(new ErrorMessage(status, exception.getMessage())) .build(); }
RuntimeExceptionUnwrappingMapper implements ExceptionMapper<RuntimeException> { @Override public Response toResponse(RuntimeException exception) { Throwable cause = exception.getCause(); if (cause instanceof DomainServiceException) { return domainServiceExceptionMapper.toResponse((DomainServiceException) cause); } int status = HttpStatus.INTERNAL_SERVER_ERROR_500; return Response.status(status) .type(MediaType.APPLICATION_JSON) .entity(new ErrorMessage(status, exception.getMessage())) .build(); } }
RuntimeExceptionUnwrappingMapper implements ExceptionMapper<RuntimeException> { @Override public Response toResponse(RuntimeException exception) { Throwable cause = exception.getCause(); if (cause instanceof DomainServiceException) { return domainServiceExceptionMapper.toResponse((DomainServiceException) cause); } int status = HttpStatus.INTERNAL_SERVER_ERROR_500; return Response.status(status) .type(MediaType.APPLICATION_JSON) .entity(new ErrorMessage(status, exception.getMessage())) .build(); } @Inject  RuntimeExceptionUnwrappingMapper(DomainServiceExceptionMapper domainServiceExceptionMapper); }
RuntimeExceptionUnwrappingMapper implements ExceptionMapper<RuntimeException> { @Override public Response toResponse(RuntimeException exception) { Throwable cause = exception.getCause(); if (cause instanceof DomainServiceException) { return domainServiceExceptionMapper.toResponse((DomainServiceException) cause); } int status = HttpStatus.INTERNAL_SERVER_ERROR_500; return Response.status(status) .type(MediaType.APPLICATION_JSON) .entity(new ErrorMessage(status, exception.getMessage())) .build(); } @Inject  RuntimeExceptionUnwrappingMapper(DomainServiceExceptionMapper domainServiceExceptionMapper); @Override Response toResponse(RuntimeException exception); }
RuntimeExceptionUnwrappingMapper implements ExceptionMapper<RuntimeException> { @Override public Response toResponse(RuntimeException exception) { Throwable cause = exception.getCause(); if (cause instanceof DomainServiceException) { return domainServiceExceptionMapper.toResponse((DomainServiceException) cause); } int status = HttpStatus.INTERNAL_SERVER_ERROR_500; return Response.status(status) .type(MediaType.APPLICATION_JSON) .entity(new ErrorMessage(status, exception.getMessage())) .build(); } @Inject  RuntimeExceptionUnwrappingMapper(DomainServiceExceptionMapper domainServiceExceptionMapper); @Override Response toResponse(RuntimeException exception);  }