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