FixedNamespaceStateRepository implements StateRepository { @Override public void setFeatureState(final FeatureState featureState) { withinNamespace(namespace, new VoidWork() { @Override void vrun() { decorated.setFeatureState(featureState); } }); } @Inject  FixedNamespaceStateRepository(@Named("togglzFixedNamespace") String namespace, @Named("togglzFixedNamespace") StateRepository decorated); @Override FeatureState getFeatureState(final Feature feature); @Override void setFeatureState(final FeatureState featureState); static R withinNamespace(String namespace, Work<R> work);  }
@Test public void setFeatureStateShouldRunWithinGivenNamespaceWhenCurrentNamespaceIsNotDefault() { NamespaceManager.set(ORIGINAL_NAMESPACE); repository = new FixedNamespaceStateRepository(ACME_NAMESPACE, new StateRepository() { @Override public void setFeatureState(FeatureState featureState) { assertEquals(ACME_NAMESPACE, NamespaceManager.get()); } @Override public FeatureState getFeatureState(Feature feature) { return null; } }); final FeatureState state = new FeatureState(TestFeature.F1) .disable() .setStrategyId("someId") .setParameter("param", "foo"); repository.setFeatureState(state); }
@Test public void setFeatureStateShouldRunWithinGivenNamespace() { repository = new FixedNamespaceStateRepository(ACME_NAMESPACE, new StateRepository() { @Override public void setFeatureState(FeatureState featureState) { assertEquals(ACME_NAMESPACE, NamespaceManager.get()); } @Override public FeatureState getFeatureState(Feature feature) { return null; } }); final FeatureState state = new FeatureState(TestFeature.F1) .disable() .setStrategyId("someId") .setParameter("param", "foo"); repository.setFeatureState(state); }