DomainServiceExceptionMapper implements ExceptionMapper<DomainServiceException> { @Override public Response toResponse(DomainServiceException exception) { final int status = this.status.get(exception.getClass()); return Response.status(status) .type(MediaType.APPLICATION_JSON_TYPE) .entity(new ErrorMessage(status, exception.getMessage())) .build(); } @Inject  DomainServiceExceptionMapper(); @Override Response toResponse(DomainServiceException exception);  }
@Test public void itShouldMapEntityNotFoundException() { EntityNotFoundException entityNotFoundException = new EntityNotFoundException( Event.class, TestConstants.EVENT_ID ); Response actual = mapper.toResponse(entityNotFoundException); assertThat(actual.getStatus()).isEqualTo(HttpStatus.NOT_FOUND_404); }
@Test public void itShouldMapAddEntityException() { AddEntityException addEntityException = new AddEntityException(new EntityNotFoundException( Event.class, TestConstants.EVENT_ID )); Response actual = mapper.toResponse(addEntityException); assertThat(actual.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422); }
@Test public void itShouldMapEntityMismatchException() { EntityMismatchException entityMismatchException = new EntityMismatchException(); Response actual = mapper.toResponse(entityMismatchException); assertThat(actual.getStatus()).isEqualTo(HttpStatus.CONFLICT_409); }