diff --git a/src/test/java/io/split/android/client/TreatmentManagerTelemetryTest.java b/src/test/java/io/split/android/client/TreatmentManagerTelemetryTest.java index feb47d7ce..74681726d 100644 --- a/src/test/java/io/split/android/client/TreatmentManagerTelemetryTest.java +++ b/src/test/java/io/split/android/client/TreatmentManagerTelemetryTest.java @@ -17,7 +17,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Set; import io.split.android.client.attributes.AttributesManager; import io.split.android.client.attributes.AttributesMerger; @@ -52,14 +51,14 @@ public class TreatmentManagerTelemetryTest { @Mock private SplitsStorage mSplitsStorage; - private Set mConfiguredFlagSets = new HashSet<>(); + private FlagSetsFilter mFlagSetsFilter; private TreatmentManagerImpl treatmentManager; private AutoCloseable mAutoCloseable; @Before public void setUp() { mAutoCloseable = MockitoAnnotations.openMocks(this); - + mFlagSetsFilter = new FlagSetsFilterImpl(new HashSet<>()); treatmentManager = new TreatmentManagerImpl( "test_key", "test_key", @@ -72,7 +71,7 @@ public void setUp() { attributesManager, attributesMerger, telemetryStorageProducer, - mConfiguredFlagSets, + mFlagSetsFilter, mSplitsStorage); when(evaluator.getTreatment(anyString(), anyString(), anyString(), anyMap())).thenReturn(new EvaluationResult("test", "label")); diff --git a/src/test/java/io/split/android/client/TreatmentManagerTest.java b/src/test/java/io/split/android/client/TreatmentManagerTest.java index edb116fd3..cd2423bf8 100644 --- a/src/test/java/io/split/android/client/TreatmentManagerTest.java +++ b/src/test/java/io/split/android/client/TreatmentManagerTest.java @@ -54,13 +54,13 @@ public class TreatmentManagerTest { ListenableEventsManager eventsManagerStub; AttributesManager attributesManager = mock(AttributesManager.class); TelemetryStorageProducer telemetryStorageProducer = mock(TelemetryStorageProducer.class); - private Set mConfiguredFlagSets; + private FlagSetsFilter mFlagSetsFilter; TreatmentManagerImpl treatmentManager; private SplitsStorage mSplitsStorage; @Before public void loadSplitsFromFile() { - mConfiguredFlagSets = new HashSet<>(); + mFlagSetsFilter = new FlagSetsFilterImpl(new HashSet<>()); mSplitsStorage = mock(SplitsStorage.class); treatmentManager = initializeTreatmentManager(); if (evaluator == null) { @@ -325,7 +325,7 @@ private TreatmentManager createTreatmentManager(String matchingKey, String bucke new KeyValidatorImpl(), new SplitValidatorImpl(), new ImpressionListenerMock(), config.labelsEnabled(), eventsManagerStub, mock(AttributesManager.class), mock(AttributesMerger.class), - mock(TelemetryStorageProducer.class), mConfiguredFlagSets, mSplitsStorage); + mock(TelemetryStorageProducer.class), mFlagSetsFilter, mSplitsStorage); } private TreatmentManagerImpl initializeTreatmentManager() { @@ -353,7 +353,7 @@ private TreatmentManagerImpl initializeTreatmentManager(Evaluator evaluator) { attributesManager, mock(AttributesMerger.class), telemetryStorageProducer, - mConfiguredFlagSets, + mFlagSetsFilter, mSplitsStorage); } diff --git a/src/test/java/io/split/android/client/TreatmentManagerWithFlagSetsTest.java b/src/test/java/io/split/android/client/TreatmentManagerWithFlagSetsTest.java index 42281896f..dc2cc12e8 100644 --- a/src/test/java/io/split/android/client/TreatmentManagerWithFlagSetsTest.java +++ b/src/test/java/io/split/android/client/TreatmentManagerWithFlagSetsTest.java @@ -55,7 +55,7 @@ public class TreatmentManagerWithFlagSetsTest { @Mock private SplitsStorage mSplitsStorage; - private Set mConfiguredFlagSets; + private FlagSetsFilter mFlagSetsFilter; private TreatmentManagerImpl mTreatmentManager; private AutoCloseable mAutoCloseable; @@ -63,24 +63,11 @@ public class TreatmentManagerWithFlagSetsTest { public void setUp() { mAutoCloseable = MockitoAnnotations.openMocks(this); - mConfiguredFlagSets = new HashSet<>(); + mFlagSetsFilter = new FlagSetsFilterImpl(new HashSet<>()); when(mEventsManager.eventAlreadyTriggered(SplitEvent.SDK_READY)).thenReturn(true); when(mEventsManager.eventAlreadyTriggered(SplitEvent.SDK_READY_FROM_CACHE)).thenReturn(true); - mTreatmentManager = new TreatmentManagerImpl( - "matching_key", - "bucketing_key", - mEvaluator, - mKeyValidator, - mSplitValidator, - mImpressionListener, - SplitClientConfig.builder().build().labelsEnabled(), - mEventsManager, - mAttributesManager, - mAttributesMerger, - mTelemetryStorageProducer, - mConfiguredFlagSets, - mSplitsStorage); + initializeTreatmentManager(); when(mEvaluator.getTreatment(anyString(), anyString(), eq("test_1"), anyMap())) .thenReturn(new EvaluationResult("result_1", "label")); @@ -129,7 +116,7 @@ public void getTreatmentsByFlagSetWithNoConfiguredSetsInvalidSetDoesNotQueryStor @Test public void getTreatmentsByFlagSetWithConfiguredSetsExistingSetQueriesStorageAndUsesEvaluator() { - mConfiguredFlagSets.add("set_1"); + mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_1"))); @@ -141,7 +128,8 @@ public void getTreatmentsByFlagSetWithConfiguredSetsExistingSetQueriesStorageAnd @Test public void getTreatmentsByFlagSetWithConfiguredSetsNonExistingSetDoesNotQueryStorageNorUseEvaluator() { - mConfiguredFlagSets.add("set_1"); + mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); + initializeTreatmentManager(); when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_split"))); @@ -151,13 +139,30 @@ public void getTreatmentsByFlagSetWithConfiguredSetsNonExistingSetDoesNotQuerySt verify(mEvaluator, times(0)).getTreatment(any(), any(), any(), anyMap()); } + private void initializeTreatmentManager() { + mTreatmentManager = new TreatmentManagerImpl( + "matching_key", + "bucketing_key", + mEvaluator, + mKeyValidator, + mSplitValidator, + mImpressionListener, + SplitClientConfig.builder().build().labelsEnabled(), + mEventsManager, + mAttributesManager, + mAttributesMerger, + mTelemetryStorageProducer, + mFlagSetsFilter, + mSplitsStorage); + } + @Test public void getTreatmentsByFlagSetReturnsCorrectFormat() { Set mockNames = new HashSet<>(); mockNames.add("test_1"); mockNames.add("test_2"); when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))).thenReturn(mockNames); - mConfiguredFlagSets.add("set_1"); + mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); Map result = mTreatmentManager.getTreatmentsByFlagSet("set_1", null, false); @@ -209,7 +214,8 @@ public void getTreatmentsByFlagSetsWithNoConfiguredSetsInvalidSetDoesNotQuerySto @Test public void getTreatmentsByFlagSetsWithConfiguredSetsExistingSetQueriesStorageForConfiguredSetOnlyAndUsesEvaluator() { - mConfiguredFlagSets.add("set_1"); + mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); + initializeTreatmentManager(); when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_1"))); @@ -221,7 +227,8 @@ public void getTreatmentsByFlagSetsWithConfiguredSetsExistingSetQueriesStorageFo @Test public void getTreatmentsByFlagSetsWithConfiguredSetsNonExistingSetDoesNotQueryStorageNorUseEvaluator() { - mConfiguredFlagSets.add("set_1"); + mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); + initializeTreatmentManager(); mTreatmentManager.getTreatmentsByFlagSets(Arrays.asList("set_2", "set_3"), null, false); @@ -301,7 +308,7 @@ public void getTreatmentsWithConfigByFlagSetWithNoConfiguredSetsInvalidSetDoesNo @Test public void getTreatmentsWithConfigByFlagSetWithConfiguredSetsExistingSetQueriesStorageAndUsesEvaluator() { - mConfiguredFlagSets.add("set_1"); + mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_1"))); @@ -313,7 +320,8 @@ public void getTreatmentsWithConfigByFlagSetWithConfiguredSetsExistingSetQueries @Test public void getTreatmentsWithConfigByFlagSetWithConfiguredSetsNonExistingSetDoesNotQueryStorageNorUseEvaluator() { - mConfiguredFlagSets.add("set_1"); + mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); + initializeTreatmentManager(); when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_split"))); @@ -329,7 +337,7 @@ public void getTreatmentsWithConfigByFlagSetReturnsCorrectFormat() { mockNames.add("test_1"); mockNames.add("test_2"); when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))).thenReturn(mockNames); - mConfiguredFlagSets.add("set_1"); + mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); Map result = mTreatmentManager.getTreatmentsWithConfigByFlagSet("set_1", null, false); @@ -381,7 +389,9 @@ public void getTreatmentsWithConfigByFlagSetsWithNoConfiguredSetsInvalidSetDoesN @Test public void getTreatmentsWithConfigByFlagSetsWithConfiguredSetsExistingSetQueriesStorageForConfiguredSetOnlyAndUsesEvaluator() { - mConfiguredFlagSets.add("set_1"); + mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); + initializeTreatmentManager(); + when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_1"))); @@ -393,7 +403,8 @@ public void getTreatmentsWithConfigByFlagSetsWithConfiguredSetsExistingSetQuerie @Test public void getTreatmentsWithConfigByFlagSetsWithConfiguredSetsNonExistingSetDoesNotQueryStorageNorUseEvaluator() { - mConfiguredFlagSets.add("set_1"); + mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); + initializeTreatmentManager(); mTreatmentManager.getTreatmentsWithConfigByFlagSets(Arrays.asList("set_2", "set_3"), null, false); diff --git a/src/test/java/io/split/android/client/localhost/shared/LocalhostSplitClientContainerImplTest.java b/src/test/java/io/split/android/client/localhost/shared/LocalhostSplitClientContainerImplTest.java index 9d855de66..2088b392a 100644 --- a/src/test/java/io/split/android/client/localhost/shared/LocalhostSplitClientContainerImplTest.java +++ b/src/test/java/io/split/android/client/localhost/shared/LocalhostSplitClientContainerImplTest.java @@ -17,8 +17,9 @@ import java.util.Collection; import java.util.HashSet; -import java.util.Set; +import io.split.android.client.FlagSetsFilter; +import io.split.android.client.FlagSetsFilterImpl; import io.split.android.client.SplitClient; import io.split.android.client.SplitClientConfig; import io.split.android.client.api.Key; @@ -52,14 +53,14 @@ public class LocalhostSplitClientContainerImplTest { private SplitClientConfig mConfig; @Mock private SplitTaskExecutor mTaskExecutor; - private Set mConfiguredSets; + private FlagSetsFilter mFlagSetsFilter; private LocalhostSplitClientContainerImpl mClientContainer; @Before public void setUp() { MockitoAnnotations.openMocks(this); when(mAttributesManagerFactory.getManager(any(), any())).thenReturn(mock(AttributesManager.class)); - mConfiguredSets = new HashSet<>(); + mFlagSetsFilter = new FlagSetsFilterImpl(new HashSet<>()); mClientContainer = getClientContainer(); } @@ -108,6 +109,6 @@ private LocalhostSplitClientContainerImpl getClientContainer() { mTelemetryStorageProducer, mEventsManagerCoordinator, mTaskExecutor, - mConfiguredSets); + mFlagSetsFilter); } } diff --git a/src/test/java/io/split/android/client/utils/SplitClientImplFactory.java b/src/test/java/io/split/android/client/utils/SplitClientImplFactory.java index 03fe34446..e20344b3e 100644 --- a/src/test/java/io/split/android/client/utils/SplitClientImplFactory.java +++ b/src/test/java/io/split/android/client/utils/SplitClientImplFactory.java @@ -4,8 +4,8 @@ import java.util.Collections; -import io.split.android.client.EvaluatorImpl; import io.split.android.client.EventsTracker; +import io.split.android.client.FlagSetsFilterImpl; import io.split.android.client.SplitClientConfig; import io.split.android.client.SplitClientImpl; import io.split.android.client.SplitFactory; @@ -39,7 +39,7 @@ public static SplitClientImpl get(Key key, SplitsStorage splitsStorage) { TreatmentManagerFactory treatmentManagerFactory = new TreatmentManagerFactoryImpl( new KeyValidatorImpl(), new SplitValidatorImpl(), new ImpressionListener.NoopImpressionListener(), false, new AttributesMergerImpl(), telemetryStorage, splitParser, - Collections.emptySet(), splitsStorage); + new FlagSetsFilterImpl(Collections.emptySet()), splitsStorage); AttributesManager attributesManager = mock(AttributesManager.class); SplitClientImpl c = new SplitClientImpl(