### Question:
ProducerBindingService { public Optional<ProducerBinding> create(ProducerBinding producerBinding) throws ValidationException { if (read(producerBinding.getKey()).isPresent()) { throw new ValidationException("Can't create because it already exists"); } producerBindingValidator.validateForCreate(producerBinding); producerBinding.setSpecification(handlerService.handleInsert(producerBinding)); return save(producerBinding); }  Optional<ProducerBinding> create(ProducerBinding producerBinding); Optional<ProducerBinding> update(ProducerBinding producerBinding); Optional<ProducerBinding> upsert(ProducerBinding producerBinding); Optional<ProducerBinding> read(ProducerBindingKey key); List<ProducerBinding> findAll(Predicate<ProducerBinding> filter); void delete(ProducerBinding producerBinding); boolean exists(ProducerBindingKey key); Optional<ProducerBinding> find(ProducerKey key);  }### Answer:
@Test public void create() { final ProducerBindingKey key = mock(ProducerBindingKey.class); final Specification specification = mock(Specification.class); final ProducerBinding entity = mock(ProducerBinding.class); when(entity.getKey()).thenReturn(key); when(producerBindingRepository.findById(key)).thenReturn(Optional.empty()); doNothing().when(producerBindingValidator).validateForCreate(entity); when(handlerService.handleInsert(entity)).thenReturn(specification); when(producerBindingRepository.save(entity)).thenReturn(entity); producerBindingService.create(entity); verify(entity).getKey(); verify(producerBindingRepository).findById(key); verify(producerBindingValidator).validateForCreate(entity); verify(handlerService).handleInsert(entity); verify(producerBindingRepository).save(entity); }