### Question:
ConsumerService { public Optional<Consumer> create(Consumer consumer) throws ValidationException { if (read(consumer.getKey()).isPresent()) { throw new ValidationException("Can't create because it already exists"); } consumerValidator.validateForCreate(consumer); consumer.setSpecification(handlerService.handleInsert(consumer)); return save(consumer); }  Optional<Consumer> create(Consumer consumer); Optional<Consumer> update(Consumer consumer); Optional<Consumer> upsert(Consumer consumer); Optional<Consumer> read(ConsumerKey key); List<Consumer> findAll(Predicate<Consumer> filter); void delete(Consumer consumer); boolean exists(ConsumerKey key);  }### Answer:
@Test public void create() { final ConsumerKey key = mock(ConsumerKey.class); final Specification specification = mock(Specification.class); final Consumer entity = mock(Consumer.class); when(entity.getKey()).thenReturn(key); when(consumerRepository.findById(key)).thenReturn(Optional.empty()); doNothing().when(consumerValidator).validateForCreate(entity); when(handlerService.handleInsert(entity)).thenReturn(specification); when(consumerRepository.save(entity)).thenReturn(entity); consumerService.create(entity); verify(entity).getKey(); verify(consumerRepository).findById(key); verify(consumerValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); verify(consumerRepository).save(entity); }