ListenableStateRepository implements StateRepository { @Override public void setFeatureState(final FeatureState featureState) { final FeatureState fromState = getFeatureState(featureState.getFeature()); delegate.setFeatureState(featureState); listeners.forEach(listener -> listener.onFeatureStateChanged(fromState, featureState)); } ListenableStateRepository(final StateRepository delegate,
                                     final Collection<FeatureStateChangedListener> listeners);  ListenableStateRepository(final StateRepository delegate,
                                     final FeatureStateChangedListener... listeners); final void addFeatureStateChangedListener(final FeatureStateChangedListener listener); @Override FeatureState getFeatureState(final Feature feature); @Override void setFeatureState(final FeatureState featureState);  }
@Test public void shouldNotifyListenersInWeightedOrder() { FeatureStateChangedListener higherPrio = mock(FeatureStateChangedListener.class); when(higherPrio.priority()).thenReturn(42); FeatureStateChangedListener lowerPrio = mock(FeatureStateChangedListener.class); when(lowerPrio.priority()).thenReturn(7); InOrder inOrder = inOrder(higherPrio, lowerPrio); final ListenableStateRepository repo = new ListenableStateRepository(delegate, higherPrio, lowerPrio); final FeatureState featureState = new FeatureState(TestFeature.F1, true); repo.setFeatureState(featureState); inOrder.verify(lowerPrio, times(1)).onFeatureStateChanged(null, featureState); inOrder.verify(higherPrio, times(1)).onFeatureStateChanged(null, featureState); }