TransactionalInstanceState implements InstanceState<T> { @Override public void update(final Consumer<StateModifier<T>> modifier) { LOGGER.debug("Updating transactional instance state for {}.", parent); stateUpdates.add(() -> parent.update(modifier)); } TransactionalInstanceState(final Collection<Runnable> stateUpdates, final InstanceState<T> parent); @Override void update(final Consumer<StateModifier<T>> modifier); @Override void reset(final Consumer<StateModifier<T>> setter); @Override Optional<String> getValue(final String key); @Override Stream<String> getKeys();  }
@Test void addsUpdate() { final List<Runnable> items = new ArrayList<>(); final InstanceState<String> parent = mock(InstanceState.class); final TransactionalInstanceState<String> s = new TransactionalInstanceState<>(items, parent); s.update(m -> { }); verify(parent, never()).update(any()); items.get(0) .run(); verify(parent).update(any()); }