FixedNamespaceStateRepository implements StateRepository { @Override public FeatureState getFeatureState(final Feature feature) { return withinNamespace(namespace, () -> decorated.getFeatureState(feature)); } @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 getFeatureStateShouldRunWithinGivenNamespace() { repository = new FixedNamespaceStateRepository(ACME_NAMESPACE, new StateRepository() { @Override public void setFeatureState(FeatureState featureState) { } @Override public FeatureState getFeatureState(Feature feature) { assertEquals(ACME_NAMESPACE, NamespaceManager.get()); return null; } }); repository.getFeatureState(TestFeature.F1); }
@Test public void getFeatureStateShouldRunWithinGivenNamespaceWhenCurrentNamespaceIsNotDefault() { NamespaceManager.set(ORIGINAL_NAMESPACE); repository = new FixedNamespaceStateRepository(ACME_NAMESPACE, new StateRepository() { @Override public void setFeatureState(FeatureState featureState) { } @Override public FeatureState getFeatureState(Feature feature) { assertEquals(ACME_NAMESPACE, NamespaceManager.get()); return null; } }); repository.getFeatureState(TestFeature.F1); }