### Question:
ProducerBindingService { public Optional<ProducerBinding> update(ProducerBinding producerBinding) throws ValidationException { var existing = read(producerBinding.getKey()); if (!existing.isPresent()) { throw new ValidationException("Can't update " + producerBinding.getKey() + " because it doesn't exist"); } producerBindingValidator.validateForUpdate(producerBinding, existing.get()); producerBinding.setSpecification(handlerService.handleUpdate(producerBinding, existing.get())); 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 update() { final ProducerBindingKey key = mock(ProducerBindingKey.class); final Specification specification = mock(Specification.class); final ProducerBinding entity = mock(ProducerBinding.class); final ProducerBinding existingEntity = mock(ProducerBinding.class); when(entity.getKey()).thenReturn(key); when(producerBindingRepository.findById(key)).thenReturn(Optional.of(existingEntity)); doNothing().when(producerBindingValidator).validateForUpdate(entity, existingEntity); when(handlerService.handleUpdate(entity, existingEntity)).thenReturn(specification); when(producerBindingRepository.save(entity)).thenReturn(entity); producerBindingService.update(entity); verify(entity).getKey(); verify(producerBindingRepository).findById(key); verify(producerBindingValidator).validateForUpdate(entity, existingEntity); verify(handlerService).handleUpdate(entity, existingEntity); verify(producerBindingRepository).save(entity); }