### Question:
ServiceExceptionMapper implements ExceptionMapper<ServiceException> { @Override public Response toResponse(ServiceException exception) { ResponseBuilder response; if (exception instanceof EntityConflictException) { response = Response.status(Status.CONFLICT); } else if (exception instanceof EntityInvalidException) { response = Response.status(Status.BAD_REQUEST); } else if (exception instanceof EntityNotFoundException) { response = Response.status(Status.NOT_FOUND); } else { response = Response.status(Status.INTERNAL_SERVER_ERROR); } return response.type(MediaType.TEXT_PLAIN).entity(exception.getMessage()).build(); }  @Override Response toResponse(ServiceException exception);  }### Answer:
@Test public void mapEntityConflictExceptionToResponse() { Response entityConflictResponse = mapper.toResponse( new EntityConflictException("Entity Conflict Message")); assertEquals(entityConflictResponse.getStatus(), Status.CONFLICT.getStatusCode()); assertEquals(entityConflictResponse.getEntity(), "Entity Conflict Message"); }
@Test public void mapEntityInvalidExceptionToResponse() { Response entityInvalidResponse = mapper.toResponse( new EntityInvalidException("Entity Invalid Message")); assertEquals(entityInvalidResponse.getStatus(), Status.BAD_REQUEST.getStatusCode()); assertEquals(entityInvalidResponse.getEntity(), "Entity Invalid Message"); }
@Test public void mapEntityNotFoundExceptionToResponse() { Response entityNotFoundResponse = mapper.toResponse( new EntityNotFoundException("Entity Not Found Message")); assertEquals(entityNotFoundResponse.getStatus(), Status.NOT_FOUND.getStatusCode()); assertEquals(entityNotFoundResponse.getEntity(), "Entity Not Found Message"); }
@Test public void mapGenericServiceExceptionToResponse() { Response serviceExceptionResponse = mapper.toResponse( new ServiceException("Generic Service Message")); assertEquals(serviceExceptionResponse.getStatus(), Status.INTERNAL_SERVER_ERROR.getStatusCode()); assertEquals(serviceExceptionResponse.getEntity(), "Generic Service Message"); }