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