diff --git a/src/androidTest/java/tests/integration/sets/FlagSetsPollingTest.java b/src/androidTest/java/tests/integration/sets/FlagSetsPollingTest.java index 8c3c095f7..ccb4e94c1 100644 --- a/src/androidTest/java/tests/integration/sets/FlagSetsPollingTest.java +++ b/src/androidTest/java/tests/integration/sets/FlagSetsPollingTest.java @@ -162,7 +162,6 @@ public void featureFlagSetsAreIgnoredWhenSetsAreNotConfigured() throws IOExcepti @Test public void queryStringIsBuiltCorrectlyWhenSetsAreConfigured() throws IOException, InterruptedException { - // 1. Initialize a factory with polling and sets set_1 & set_2 configured. createFactory(mContext, mRoomDb, "set_x", "set_x", "set_3", "set_2", "set_3", "set_ww", "invalid+"); boolean awaitFirst = firstChangeLatch.await(5, TimeUnit.SECONDS); diff --git a/src/androidTest/java/tests/integration/userconsent/UserConsentModeDebugTest.kt b/src/androidTest/java/tests/integration/userconsent/UserConsentModeDebugTest.kt index b162d2a54..4c0d9eb02 100644 --- a/src/androidTest/java/tests/integration/userconsent/UserConsentModeDebugTest.kt +++ b/src/androidTest/java/tests/integration/userconsent/UserConsentModeDebugTest.kt @@ -231,7 +231,7 @@ class UserConsentModeDebugTest { } else if (uri.path.contains("/splitChanges")) { if (mChangeHit == 0) { mChangeHit+=1 - return getSplitsMockResponse("", "") + return getSplitsMockResponse("") } return HttpResponseMock(200, IntegrationHelper.emptySplitChanges(99999999, 99999999)) } else if (uri.path.contains("/testImpressions/bulk")) { @@ -259,7 +259,7 @@ class UserConsentModeDebugTest { } } - private fun getSplitsMockResponse(since: String, till: String): HttpResponseMock { + private fun getSplitsMockResponse(since: String): HttpResponseMock { return HttpResponseMock(200, loadSplitChanges()) } diff --git a/src/androidTest/java/tests/integration/userconsent/UserConsentModeNoneTest.kt b/src/androidTest/java/tests/integration/userconsent/UserConsentModeNoneTest.kt index dddec5f6a..106bfd65b 100644 --- a/src/androidTest/java/tests/integration/userconsent/UserConsentModeNoneTest.kt +++ b/src/androidTest/java/tests/integration/userconsent/UserConsentModeNoneTest.kt @@ -232,7 +232,7 @@ class UserConsentModeNoneTest { } else if (uri.path.contains("/splitChanges")) { if (mChangeHit == 0) { mChangeHit+=1 - return getSplitsMockResponse("", "") + return getSplitsMockResponse("") } return HttpResponseMock(200, IntegrationHelper.emptySplitChanges(99999999, 99999999)) } else if (uri.path.contains("/testImpressions/bulk")) { @@ -260,7 +260,7 @@ class UserConsentModeNoneTest { } } - private fun getSplitsMockResponse(since: String, till: String): HttpResponseMock { + private fun getSplitsMockResponse(since: String): HttpResponseMock { return HttpResponseMock(200, loadSplitChanges()) } diff --git a/src/androidTest/java/tests/integration/userconsent/UserConsentModeOptimizedTest.kt b/src/androidTest/java/tests/integration/userconsent/UserConsentModeOptimizedTest.kt index 4a6ab033b..28e9fdb77 100644 --- a/src/androidTest/java/tests/integration/userconsent/UserConsentModeOptimizedTest.kt +++ b/src/androidTest/java/tests/integration/userconsent/UserConsentModeOptimizedTest.kt @@ -242,7 +242,7 @@ class UserConsentModeOptimizedTest { } else if (uri.path.contains("/splitChanges")) { if (mChangeHit == 0) { mChangeHit+=1 - return getSplitsMockResponse("", "") + return getSplitsMockResponse("") } return HttpResponseMock(200, IntegrationHelper.emptySplitChanges(99999999, 99999999)) } else if (uri.path.contains("/testImpressions/bulk")) { @@ -270,7 +270,7 @@ class UserConsentModeOptimizedTest { } } - private fun getSplitsMockResponse(since: String, till: String): HttpResponseMock { + private fun getSplitsMockResponse(since: String): HttpResponseMock { return HttpResponseMock(200, loadSplitChanges()) } diff --git a/src/main/java/io/split/android/client/FlagSetsFilterImpl.java b/src/main/java/io/split/android/client/FlagSetsFilterImpl.java index 84ab5c839..d8c731280 100644 --- a/src/main/java/io/split/android/client/FlagSetsFilterImpl.java +++ b/src/main/java/io/split/android/client/FlagSetsFilterImpl.java @@ -1,5 +1,6 @@ package io.split.android.client; +import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -8,7 +9,7 @@ public class FlagSetsFilterImpl implements FlagSetsFilter { private final boolean mShouldFilter; private final Set mFlagSets; - public FlagSetsFilterImpl(Set flagSets) { + public FlagSetsFilterImpl(Collection flagSets) { mFlagSets = new HashSet<>(flagSets); mShouldFilter = !mFlagSets.isEmpty(); } diff --git a/src/main/java/io/split/android/client/SplitFactoryImpl.java b/src/main/java/io/split/android/client/SplitFactoryImpl.java index 11519d18b..e798dcdcd 100644 --- a/src/main/java/io/split/android/client/SplitFactoryImpl.java +++ b/src/main/java/io/split/android/client/SplitFactoryImpl.java @@ -182,7 +182,7 @@ public void taskExecuted(@NonNull SplitTaskExecutionInfo taskInfo) { FlagSetsFilter flagSetsFilter = null; if (filters.get(SplitFilter.Type.BY_SET) != null) { - flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>(filters.get(SplitFilter.Type.BY_SET).getValues())); + flagSetsFilter = new FlagSetsFilterImpl(filters.get(SplitFilter.Type.BY_SET).getValues()); } SplitTaskFactory splitTaskFactory = new SplitTaskFactoryImpl( diff --git a/src/main/java/io/split/android/client/SplitFilter.java b/src/main/java/io/split/android/client/SplitFilter.java index 908f01c34..38b1a0721 100644 --- a/src/main/java/io/split/android/client/SplitFilter.java +++ b/src/main/java/io/split/android/client/SplitFilter.java @@ -86,7 +86,7 @@ public static SplitFilter bySet(@NonNull List values) { SplitFilter(Type type, List values, SplitFilterValidator validator) { mType = type; - SplitFilterValidator.ValidationResult validationResult = validator.cleanup(values); + SplitFilterValidator.ValidationResult validationResult = validator.cleanup("SDK config", values); mValues = validationResult.getValues(); mInvalidValueCount = validationResult.getInvalidValueCount(); } diff --git a/src/main/java/io/split/android/client/localhost/LocalhostSplitClient.java b/src/main/java/io/split/android/client/localhost/LocalhostSplitClient.java index 941f3ee7a..c70d79420 100644 --- a/src/main/java/io/split/android/client/localhost/LocalhostSplitClient.java +++ b/src/main/java/io/split/android/client/localhost/LocalhostSplitClient.java @@ -12,7 +12,6 @@ import java.util.Map; import java.util.Set; -import io.split.android.client.Evaluator; import io.split.android.client.EvaluatorImpl; import io.split.android.client.FlagSetsFilter; import io.split.android.client.SplitClient; diff --git a/src/main/java/io/split/android/client/localhost/LocalhostSplitFactory.java b/src/main/java/io/split/android/client/localhost/LocalhostSplitFactory.java index 0948fad70..e65838367 100644 --- a/src/main/java/io/split/android/client/localhost/LocalhostSplitFactory.java +++ b/src/main/java/io/split/android/client/localhost/LocalhostSplitFactory.java @@ -85,7 +85,7 @@ public LocalhostSplitFactory(String key, Context context, if (!groupedFilters.isEmpty()) { SplitFilter bySetFilter = groupedFilters.get(SplitFilter.Type.BY_SET); if (bySetFilter != null) { - flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>(bySetFilter.getValues())); + flagSetsFilter = new FlagSetsFilterImpl(bySetFilter.getValues()); } } } diff --git a/src/main/java/io/split/android/client/localhost/LocalhostSplitsStorage.java b/src/main/java/io/split/android/client/localhost/LocalhostSplitsStorage.java index 76bc60b3d..989d9a16c 100644 --- a/src/main/java/io/split/android/client/localhost/LocalhostSplitsStorage.java +++ b/src/main/java/io/split/android/client/localhost/LocalhostSplitsStorage.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -126,7 +127,7 @@ public void clear() { @NonNull @Override - public Set getNamesByFlagSets(List sets) { + public Set getNamesByFlagSets(Collection sets) { Set namesToReturn = new HashSet<>(); if (sets == null || sets.isEmpty()) { return namesToReturn; diff --git a/src/main/java/io/split/android/client/service/splits/FeatureFlagProcessStrategy.java b/src/main/java/io/split/android/client/service/splits/FeatureFlagProcessStrategy.java index f61871de0..1cffb6669 100644 --- a/src/main/java/io/split/android/client/service/splits/FeatureFlagProcessStrategy.java +++ b/src/main/java/io/split/android/client/service/splits/FeatureFlagProcessStrategy.java @@ -68,7 +68,7 @@ public void process(List activeFeatureFlags, List archivedFeatureF Set newSets = new HashSet<>(); for (String set : featureFlag.sets) { if (mFlagSetsFilter.intersect(set)) { - newSets.add(set); // Remove all sets that don't match the configured sets + newSets.add(set); // Add the flag set to the valid group // Since the feature flag has at least one set that matches the configured sets, // we process it according to its status shouldArchive = false; @@ -78,6 +78,7 @@ public void process(List activeFeatureFlags, List archivedFeatureF if (shouldArchive) { archivedFeatureFlags.add(featureFlag); } else { + // Replace the feature flag sets with the intersection of the configured sets and the feature flag sets featureFlag.sets = newSets; mStatusProcessStrategy.process(activeFeatureFlags, archivedFeatureFlags, featureFlag); } diff --git a/src/main/java/io/split/android/client/service/workmanager/SplitsSyncWorker.java b/src/main/java/io/split/android/client/service/workmanager/SplitsSyncWorker.java index 0745bdb45..982e2fcae 100644 --- a/src/main/java/io/split/android/client/service/workmanager/SplitsSyncWorker.java +++ b/src/main/java/io/split/android/client/service/workmanager/SplitsSyncWorker.java @@ -53,7 +53,7 @@ public SplitsSyncWorker(@NonNull Context context, TelemetryStorage telemetryStorage = StorageFactory.getTelemetryStorage(shouldRecordTelemetry); SplitChangeProcessor splitChangeProcessor = new SplitChangeProcessor(filter, (filter != null && filter.getType() == SplitFilter.Type.BY_SET) ? - new FlagSetsFilterImpl(new HashSet<>(filter.getValues())) : null); + new FlagSetsFilterImpl(filter.getValues()) : null); SplitsSyncHelper splitsSyncHelper = new SplitsSyncHelper(splitsFetcher, splitsStorage, splitChangeProcessor, diff --git a/src/main/java/io/split/android/client/storage/splits/SplitsStorage.java b/src/main/java/io/split/android/client/storage/splits/SplitsStorage.java index d152243b5..62af70e7b 100644 --- a/src/main/java/io/split/android/client/storage/splits/SplitsStorage.java +++ b/src/main/java/io/split/android/client/storage/splits/SplitsStorage.java @@ -3,6 +3,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; @@ -35,5 +36,5 @@ public interface SplitsStorage { void clear(); @NonNull - Set getNamesByFlagSets(List flagSets); + Set getNamesByFlagSets(Collection flagSets); } diff --git a/src/main/java/io/split/android/client/storage/splits/SplitsStorageImpl.java b/src/main/java/io/split/android/client/storage/splits/SplitsStorageImpl.java index 2f3eb99f6..b143c209c 100644 --- a/src/main/java/io/split/android/client/storage/splits/SplitsStorageImpl.java +++ b/src/main/java/io/split/android/client/storage/splits/SplitsStorageImpl.java @@ -6,6 +6,7 @@ import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -150,7 +151,7 @@ public void clear() { @NonNull @Override - public Set getNamesByFlagSets(List sets) { + public Set getNamesByFlagSets(Collection sets) { Set namesToReturn = new HashSet<>(); if (sets == null || sets.isEmpty()) { return namesToReturn; diff --git a/src/main/java/io/split/android/client/validators/FlagSetsValidatorImpl.java b/src/main/java/io/split/android/client/validators/FlagSetsValidatorImpl.java index 5e14a45a3..a9dbcb6b5 100644 --- a/src/main/java/io/split/android/client/validators/FlagSetsValidatorImpl.java +++ b/src/main/java/io/split/android/client/validators/FlagSetsValidatorImpl.java @@ -2,9 +2,12 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.TreeSet; +import io.split.android.client.FlagSetsFilter; import io.split.android.client.utils.logger.Logger; public class FlagSetsValidatorImpl implements SplitFilterValidator { @@ -19,7 +22,7 @@ public class FlagSetsValidatorImpl implements SplitFilterValidator { * @return list of unique alphanumerically ordered valid flag sets */ @Override - public ValidationResult cleanup(List values) { + public ValidationResult cleanup(String method, List values) { if (values == null || values.isEmpty()) { return new ValidationResult(Collections.emptyList(), 0); } @@ -34,12 +37,12 @@ public ValidationResult cleanup(List values) { } if (set.trim().length() != set.length()) { - Logger.w("SDK config: Flag Set name " + set + " has extra whitespace, trimming"); + Logger.w(method + ": Flag Set name " + set + " has extra whitespace, trimming"); set = set.trim(); } if (!set.toLowerCase().equals(set)) { - Logger.w("SDK config: Flag Set name "+set+" should be all lowercase - converting string to lowercase"); + Logger.w(method + ": Flag Set name "+set+" should be all lowercase - converting string to lowercase"); set = set.toLowerCase(); } @@ -47,7 +50,7 @@ public ValidationResult cleanup(List values) { cleanedUpSets.add(set); } else { invalidValueCount++; - Logger.w("SDK config: you passed "+ set +", Flag Set must adhere to the regular expressions "+ FLAG_SET_REGEX +". This means a Flag Set must be start with a letter, be in lowercase, alphanumeric and have a max length of 50 characters. "+ set +" was discarded."); + Logger.w(method + ": you passed "+ set +", Flag Set must adhere to the regular expressions "+ FLAG_SET_REGEX +". This means a Flag Set must be start with a letter, be in lowercase, alphanumeric and have a max length of 50 characters. "+ set +" was discarded."); } } @@ -58,4 +61,27 @@ public ValidationResult cleanup(List values) { public boolean isValid(String value) { return value != null && value.trim().matches(FLAG_SET_REGEX); } + + @Override + public Set items(List values, FlagSetsFilter flagSetsFilter) { + Set setsToReturn = new HashSet<>(); + + if (values == null || values.isEmpty()) { + return setsToReturn; + } + + for (String flagSet : values) { + if (!isValid(flagSet)) { + continue; + } + + if (flagSetsFilter != null && !flagSetsFilter.intersect(flagSet)) { + continue; + } + + setsToReturn.add(flagSet); + } + + return setsToReturn; + } } diff --git a/src/main/java/io/split/android/client/validators/SplitFilterValidator.java b/src/main/java/io/split/android/client/validators/SplitFilterValidator.java index 110043d47..b5f0d1b2b 100644 --- a/src/main/java/io/split/android/client/validators/SplitFilterValidator.java +++ b/src/main/java/io/split/android/client/validators/SplitFilterValidator.java @@ -1,13 +1,18 @@ package io.split.android.client.validators; import java.util.List; +import java.util.Set; + +import io.split.android.client.FlagSetsFilter; public interface SplitFilterValidator { - ValidationResult cleanup(List values); + ValidationResult cleanup(String method, List values); boolean isValid(String value); + Set items(List values, FlagSetsFilter flagSetsFilter); + class ValidationResult { private final List mValues; diff --git a/src/main/java/io/split/android/client/validators/TreatmentManagerImpl.java b/src/main/java/io/split/android/client/validators/TreatmentManagerImpl.java index 3d4be2839..8a5511467 100644 --- a/src/main/java/io/split/android/client/validators/TreatmentManagerImpl.java +++ b/src/main/java/io/split/android/client/validators/TreatmentManagerImpl.java @@ -186,7 +186,7 @@ public Map getTreatmentsByFlagSet(@NonNull String flagSet, @Null String validationTag = ValidationTag.GET_TREATMENTS_BY_FLAG_SET; Set names = new HashSet<>(); try { - names = getNamesFromSet(validationTag, Collections.singletonList(flagSet)); + names = getNamesFromSet(Collections.singletonList(flagSet)); if (isClientDestroyed) { mValidationLogger.e(CLIENT_DESTROYED_MESSAGE, validationTag); return controlTreatmentsForSplits(new ArrayList<>(names), validationTag); @@ -211,7 +211,7 @@ public Map getTreatmentsByFlagSets(@NonNull List flagSet String validationTag = ValidationTag.GET_TREATMENTS_BY_FLAG_SETS; Set names = new HashSet<>(); try { - names = getNamesFromSet(validationTag, flagSets); + names = getNamesFromSet(flagSets); if (isClientDestroyed) { mValidationLogger.e(CLIENT_DESTROYED_MESSAGE, validationTag); return controlTreatmentsForSplits(new ArrayList<>(names), validationTag); @@ -236,7 +236,7 @@ public Map getTreatmentsWithConfigByFlagSet(@NonNull String String validationTag = ValidationTag.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET; Set names = new HashSet<>(); try { - names = getNamesFromSet(validationTag, Collections.singletonList(flagSet)); + names = getNamesFromSet(Collections.singletonList(flagSet)); if (isClientDestroyed) { mValidationLogger.e(CLIENT_DESTROYED_MESSAGE, validationTag); return controlTreatmentsForSplitsWithConfig(new ArrayList<>(names), validationTag); @@ -261,7 +261,7 @@ public Map getTreatmentsWithConfigByFlagSets(@NonNull List< String validationTag = ValidationTag.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS; Set names = new HashSet<>(); try { - names = getNamesFromSet(validationTag, flagSets); + names = getNamesFromSet(flagSets); if (isClientDestroyed) { mValidationLogger.e(CLIENT_DESTROYED_MESSAGE, validationTag); return controlTreatmentsForSplitsWithConfig(new ArrayList<>(names), validationTag); @@ -402,30 +402,9 @@ private void recordLatency(Method treatment, long startTime) { } @NonNull - private Set getNamesFromSet(String validationTag, - @NonNull List flagSets) { + private Set getNamesFromSet(@NonNull List flagSets) { - if (flagSets == null) { - return new HashSet<>(); - } - - List setsToEvaluate = new ArrayList<>(); - for (String flagSet : flagSets) { - if (setsToEvaluate.contains(flagSet)) { - continue; - } - - boolean isValid = mFlagSetsValidator.isValid(flagSet); - boolean isConfigured = mFlagSetsFilter.intersect(flagSet); - - if (!isValid) { - mValidationLogger.e("you passed " + flagSet + " which is not valid.", validationTag); - } else if (!isConfigured) { - mValidationLogger.e("you passed " + flagSet + " which is not defined in the configuration.", validationTag); - } else { - setsToEvaluate.add(flagSet); - } - } + Set setsToEvaluate = mFlagSetsValidator.items(flagSets, mFlagSetsFilter); if (setsToEvaluate.isEmpty()) { return new HashSet<>(); diff --git a/src/test/java/io/split/android/client/TreatmentManagerWithFlagSetsTest.java b/src/test/java/io/split/android/client/TreatmentManagerWithFlagSetsTest.java index dc2cc12e8..dc1f4efc5 100644 --- a/src/test/java/io/split/android/client/TreatmentManagerWithFlagSetsTest.java +++ b/src/test/java/io/split/android/client/TreatmentManagerWithFlagSetsTest.java @@ -94,18 +94,18 @@ public void getTreatmentsByFlagSetDestroyedDoesNotUseEvaluator() { @Test public void getTreatmentsByFlagSetWithNoConfiguredSetsQueriesStorageAndUsesEvaluator() { - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_1"))); mTreatmentManager.getTreatmentsByFlagSet("set_1", null, false); - verify(mSplitsStorage).getNamesByFlagSets(Collections.singletonList("set_1")); + verify(mSplitsStorage).getNamesByFlagSets(Collections.singleton("set_1")); verify(mEvaluator).getTreatment(eq("matching_key"), eq("bucketing_key"), eq("test_1"), anyMap()); } @Test public void getTreatmentsByFlagSetWithNoConfiguredSetsInvalidSetDoesNotQueryStorageNorUseEvaluator() { - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_split"))); mTreatmentManager.getTreatmentsByFlagSet("SET!", null, false); @@ -117,12 +117,12 @@ public void getTreatmentsByFlagSetWithNoConfiguredSetsInvalidSetDoesNotQueryStor @Test public void getTreatmentsByFlagSetWithConfiguredSetsExistingSetQueriesStorageAndUsesEvaluator() { mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_1"))); mTreatmentManager.getTreatmentsByFlagSet("set_1", null, false); - verify(mSplitsStorage).getNamesByFlagSets(Collections.singletonList("set_1")); + verify(mSplitsStorage).getNamesByFlagSets(Collections.singleton("set_1")); verify(mEvaluator).getTreatment(eq("matching_key"), eq("bucketing_key"), eq("test_1"), anyMap()); } @@ -130,7 +130,7 @@ public void getTreatmentsByFlagSetWithConfiguredSetsExistingSetQueriesStorageAnd public void getTreatmentsByFlagSetWithConfiguredSetsNonExistingSetDoesNotQueryStorageNorUseEvaluator() { mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); initializeTreatmentManager(); - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_split"))); mTreatmentManager.getTreatmentsByFlagSet("set_2", null, false); @@ -161,7 +161,7 @@ public void getTreatmentsByFlagSetReturnsCorrectFormat() { Set mockNames = new HashSet<>(); mockNames.add("test_1"); mockNames.add("test_2"); - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))).thenReturn(mockNames); + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))).thenReturn(mockNames); mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); Map result = mTreatmentManager.getTreatmentsByFlagSet("set_1", null, false); @@ -173,7 +173,7 @@ public void getTreatmentsByFlagSetReturnsCorrectFormat() { @Test public void getTreatmentsByFlagSetRecordsTelemetry() { - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))).thenReturn(Collections.singleton("test_1")); + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))).thenReturn(Collections.singleton("test_1")); mTreatmentManager.getTreatmentsByFlagSet("set_1", null, false); @@ -191,24 +191,24 @@ public void getTreatmentsByFlagSetsDestroyedDoesNotUseEvaluator() { @Test public void getTreatmentsByFlagSetsWithNoConfiguredSetsQueriesStorageAndUsesEvaluator() { - when(mSplitsStorage.getNamesByFlagSets(Arrays.asList("set_1", "set_2"))) + when(mSplitsStorage.getNamesByFlagSets(new HashSet<>(Arrays.asList("set_1", "set_2")))) .thenReturn(new HashSet<>(Arrays.asList("test_1", "test_2"))); mTreatmentManager.getTreatmentsByFlagSets(Arrays.asList("set_1", "set_2"), null, false); - verify(mSplitsStorage).getNamesByFlagSets(Arrays.asList("set_1", "set_2")); + verify(mSplitsStorage).getNamesByFlagSets(new HashSet<>(Arrays.asList("set_1", "set_2"))); verify(mEvaluator).getTreatment(anyString(), anyString(), eq("test_1"), anyMap()); verify(mEvaluator).getTreatment(anyString(), anyString(), eq("test_2"), anyMap()); } @Test public void getTreatmentsByFlagSetsWithNoConfiguredSetsInvalidSetDoesNotQueryStorageForInvalidSet() { - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_1"))); mTreatmentManager.getTreatmentsByFlagSets(Arrays.asList("set_1", "SET!"), null, false); - verify(mSplitsStorage).getNamesByFlagSets(Collections.singletonList("set_1")); + verify(mSplitsStorage).getNamesByFlagSets(Collections.singleton("set_1")); verify(mEvaluator).getTreatment(any(), any(), eq("test_1"), anyMap()); } @@ -216,12 +216,12 @@ public void getTreatmentsByFlagSetsWithNoConfiguredSetsInvalidSetDoesNotQuerySto public void getTreatmentsByFlagSetsWithConfiguredSetsExistingSetQueriesStorageForConfiguredSetOnlyAndUsesEvaluator() { mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); initializeTreatmentManager(); - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_1"))); mTreatmentManager.getTreatmentsByFlagSets(Arrays.asList("set_1", "set_2"), null, false); - verify(mSplitsStorage).getNamesByFlagSets(Collections.singletonList("set_1")); + verify(mSplitsStorage).getNamesByFlagSets(Collections.singleton("set_1")); verify(mEvaluator).getTreatment(anyString(), anyString(), eq("test_1"), anyMap()); } @@ -241,7 +241,7 @@ public void getTreatmentsByFlagSetsReturnsCorrectFormat() { Set mockNames = new HashSet<>(); mockNames.add("test_1"); mockNames.add("test_2"); - when(mSplitsStorage.getNamesByFlagSets(Arrays.asList("set_1", "set_2"))).thenReturn(mockNames); + when(mSplitsStorage.getNamesByFlagSets(new HashSet<>(Arrays.asList("set_1", "set_2")))).thenReturn(mockNames); Map result = mTreatmentManager.getTreatmentsByFlagSets(Arrays.asList("set_1", "set_2"), null, false); @@ -254,7 +254,7 @@ public void getTreatmentsByFlagSetsReturnsCorrectFormat() { public void getTreatmentsByFlagSetsWithDuplicatedSetDeduplicates() { mTreatmentManager.getTreatmentsByFlagSets(Arrays.asList("set_1", "set_1"), null, false); - verify(mSplitsStorage).getNamesByFlagSets(Collections.singletonList("set_1")); + verify(mSplitsStorage).getNamesByFlagSets(Collections.singleton("set_1")); } @Test @@ -268,7 +268,7 @@ public void getTreatmentsByFlagSetsWithNullSetListReturnsEmpty() { @Test public void getTreatmentsByFlagSetsRecordsTelemetry() { - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))).thenReturn(Collections.singleton("test_1")); + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))).thenReturn(Collections.singleton("test_1")); mTreatmentManager.getTreatmentsByFlagSets(Arrays.asList("set_1", "set_2"), null, false); @@ -286,18 +286,18 @@ public void getTreatmentsWithConfigByFlagSetDestroyedDoesNotUseEvaluator() { @Test public void getTreatmentsWithConfigByFlagSetWithNoConfiguredSetsQueriesStorageAndUsesEvaluator() { - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) - .thenReturn(new HashSet<>(Collections.singletonList("test_1"))); + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))) + .thenReturn(Collections.singleton("test_1")); mTreatmentManager.getTreatmentsWithConfigByFlagSet("set_1", null, false); - verify(mSplitsStorage).getNamesByFlagSets(Collections.singletonList("set_1")); + verify(mSplitsStorage).getNamesByFlagSets(Collections.singleton("set_1")); verify(mEvaluator).getTreatment(eq("matching_key"), eq("bucketing_key"), eq("test_1"), anyMap()); } @Test public void getTreatmentsWithConfigByFlagSetWithNoConfiguredSetsInvalidSetDoesNotQueryStorageNorUseEvaluator() { - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_split"))); mTreatmentManager.getTreatmentsWithConfigByFlagSet("SET!", null, false); @@ -309,12 +309,12 @@ public void getTreatmentsWithConfigByFlagSetWithNoConfiguredSetsInvalidSetDoesNo @Test public void getTreatmentsWithConfigByFlagSetWithConfiguredSetsExistingSetQueriesStorageAndUsesEvaluator() { mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_1"))); mTreatmentManager.getTreatmentsWithConfigByFlagSet("set_1", null, false); - verify(mSplitsStorage).getNamesByFlagSets(Collections.singletonList("set_1")); + verify(mSplitsStorage).getNamesByFlagSets(Collections.singleton("set_1")); verify(mEvaluator).getTreatment(eq("matching_key"), eq("bucketing_key"), eq("test_1"), anyMap()); } @@ -322,7 +322,7 @@ public void getTreatmentsWithConfigByFlagSetWithConfiguredSetsExistingSetQueries public void getTreatmentsWithConfigByFlagSetWithConfiguredSetsNonExistingSetDoesNotQueryStorageNorUseEvaluator() { mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); initializeTreatmentManager(); - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_split"))); mTreatmentManager.getTreatmentsWithConfigByFlagSet("set_2", null, false); @@ -336,7 +336,7 @@ public void getTreatmentsWithConfigByFlagSetReturnsCorrectFormat() { Set mockNames = new HashSet<>(); mockNames.add("test_1"); mockNames.add("test_2"); - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))).thenReturn(mockNames); + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))).thenReturn(mockNames); mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); Map result = mTreatmentManager.getTreatmentsWithConfigByFlagSet("set_1", null, false); @@ -348,7 +348,7 @@ public void getTreatmentsWithConfigByFlagSetReturnsCorrectFormat() { @Test public void getTreatmentsWithConfigByFlagSetRecordsTelemetry() { - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))).thenReturn(Collections.singleton("test_1")); + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))).thenReturn(Collections.singleton("test_1")); mTreatmentManager.getTreatmentsWithConfigByFlagSet("set_1", null, false); @@ -366,24 +366,24 @@ public void getTreatmentsWithConfigByFlagSetsDestroyedDoesNotUseEvaluator() { @Test public void getTreatmentsWithConfigByFlagSetsWithNoConfiguredSetsQueriesStorageAndUsesEvaluator() { - when(mSplitsStorage.getNamesByFlagSets(Arrays.asList("set_1", "set_2"))) + when(mSplitsStorage.getNamesByFlagSets(new HashSet<>(Arrays.asList("set_1", "set_2")))) .thenReturn(new HashSet<>(Arrays.asList("test_1", "test_2"))); mTreatmentManager.getTreatmentsWithConfigByFlagSets(Arrays.asList("set_1", "set_2"), null, false); - verify(mSplitsStorage).getNamesByFlagSets(Arrays.asList("set_1", "set_2")); + verify(mSplitsStorage).getNamesByFlagSets(new HashSet<>(Arrays.asList("set_1", "set_2"))); verify(mEvaluator).getTreatment(anyString(), anyString(), eq("test_1"), anyMap()); verify(mEvaluator).getTreatment(anyString(), anyString(), eq("test_2"), anyMap()); } @Test public void getTreatmentsWithConfigByFlagSetsWithNoConfiguredSetsInvalidSetDoesNotQueryStorageForInvalidSet() { - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_1"))); mTreatmentManager.getTreatmentsWithConfigByFlagSets(Arrays.asList("set_1", "SET!"), null, false); - verify(mSplitsStorage).getNamesByFlagSets(Collections.singletonList("set_1")); + verify(mSplitsStorage).getNamesByFlagSets(Collections.singleton("set_1")); verify(mEvaluator).getTreatment(any(), any(), eq("test_1"), anyMap()); } @@ -392,12 +392,12 @@ public void getTreatmentsWithConfigByFlagSetsWithConfiguredSetsExistingSetQuerie mFlagSetsFilter = new FlagSetsFilterImpl(Collections.singleton("set_1")); initializeTreatmentManager(); - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))) + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))) .thenReturn(new HashSet<>(Collections.singletonList("test_1"))); mTreatmentManager.getTreatmentsWithConfigByFlagSets(Arrays.asList("set_1", "set_2"), null, false); - verify(mSplitsStorage).getNamesByFlagSets(Collections.singletonList("set_1")); + verify(mSplitsStorage).getNamesByFlagSets(Collections.singleton("set_1")); verify(mEvaluator).getTreatment(anyString(), anyString(), eq("test_1"), anyMap()); } @@ -417,7 +417,7 @@ public void getTreatmentsWithConfigByFlagSetsReturnsCorrectFormat() { Set mockNames = new HashSet<>(); mockNames.add("test_1"); mockNames.add("test_2"); - when(mSplitsStorage.getNamesByFlagSets(Arrays.asList("set_1", "set_2"))).thenReturn(mockNames); + when(mSplitsStorage.getNamesByFlagSets(new HashSet<>(Arrays.asList("set_1", "set_2")))).thenReturn(mockNames); Map result = mTreatmentManager.getTreatmentsWithConfigByFlagSets(Arrays.asList("set_1", "set_2"), null, false); @@ -430,7 +430,7 @@ public void getTreatmentsWithConfigByFlagSetsReturnsCorrectFormat() { public void getTreatmentsWithConfigByFlagSetsWithDuplicatedSetDeduplicates() { mTreatmentManager.getTreatmentsWithConfigByFlagSets(Arrays.asList("set_1", "set_1"), null, false); - verify(mSplitsStorage).getNamesByFlagSets(Collections.singletonList("set_1")); + verify(mSplitsStorage).getNamesByFlagSets(Collections.singleton("set_1")); } @Test @@ -444,7 +444,7 @@ public void getTreatmentsWithConfigByFlagSetsWithNullSetListReturnsEmpty() { @Test public void getTreatmentsWithConfigByFlagSetsRecordsTelemetry() { - when(mSplitsStorage.getNamesByFlagSets(Collections.singletonList("set_1"))).thenReturn(Collections.singleton("test_1")); + when(mSplitsStorage.getNamesByFlagSets(Collections.singleton("set_1"))).thenReturn(Collections.singleton("test_1")); mTreatmentManager.getTreatmentsWithConfigByFlagSets(Arrays.asList("set_1", "set_2"), null, false); diff --git a/src/test/java/io/split/android/client/validators/FlagSetsValidatorImplTest.java b/src/test/java/io/split/android/client/validators/FlagSetsValidatorImplTest.java index 72e3482db..573d74a9e 100644 --- a/src/test/java/io/split/android/client/validators/FlagSetsValidatorImplTest.java +++ b/src/test/java/io/split/android/client/validators/FlagSetsValidatorImplTest.java @@ -15,21 +15,21 @@ public class FlagSetsValidatorImplTest { @Test public void nullInputReturnsEmptyList() { - SplitFilterValidator.ValidationResult result = mValidator.cleanup(null); + SplitFilterValidator.ValidationResult result = mValidator.cleanup("method", null); assertTrue(result.getValues().isEmpty()); assertEquals(0, result.getInvalidValueCount()); } @Test public void emptyInputReturnsEmptyList() { - SplitFilterValidator.ValidationResult result = mValidator.cleanup(Collections.emptyList()); + SplitFilterValidator.ValidationResult result = mValidator.cleanup("method", Collections.emptyList()); assertTrue(result.getValues().isEmpty()); assertEquals(0, result.getInvalidValueCount()); } @Test public void duplicatedInputValuesAreRemoved() { - SplitFilterValidator.ValidationResult result = mValidator.cleanup(Arrays.asList("set1", "set1")); + SplitFilterValidator.ValidationResult result = mValidator.cleanup("method", Arrays.asList("set1", "set1")); assertEquals(1, result.getValues().size()); assertTrue(result.getValues().contains("set1")); assertEquals(0, result.getInvalidValueCount()); @@ -37,7 +37,7 @@ public void duplicatedInputValuesAreRemoved() { @Test public void valuesAreSortedAlphanumerically() { - SplitFilterValidator.ValidationResult result = mValidator.cleanup(Arrays.asList("set2", "set1", "set_1", "1set")); + SplitFilterValidator.ValidationResult result = mValidator.cleanup("method", Arrays.asList("set2", "set1", "set_1", "1set")); assertEquals(4, result.getValues().size()); assertEquals("1set", result.getValues().get(0)); assertEquals("set1", result.getValues().get(1)); @@ -48,7 +48,7 @@ public void valuesAreSortedAlphanumerically() { @Test public void invalidValuesAreRemoved() { - SplitFilterValidator.ValidationResult result = mValidator.cleanup(Arrays.asList("set1", "set2", "set_1", "set-1", "set 1", "set 2")); + SplitFilterValidator.ValidationResult result = mValidator.cleanup("method", Arrays.asList("set1", "set2", "set_1", "set-1", "set 1", "set 2")); assertEquals(3, result.getValues().size()); assertEquals("set1", result.getValues().get(0)); assertEquals("set2", result.getValues().get(1)); @@ -59,7 +59,7 @@ public void invalidValuesAreRemoved() { @Test public void setWithMoreThan50CharsIsRemoved() { String longSet = "abcdfghijklmnopqrstuvwxyz1234567890abcdfghijklmnopq"; - SplitFilterValidator.ValidationResult result = mValidator.cleanup(Arrays.asList("set1", longSet)); + SplitFilterValidator.ValidationResult result = mValidator.cleanup("method", Arrays.asList("set1", longSet)); assertEquals(51, longSet.length()); assertEquals(1, result.getValues().size()); assertEquals("set1", result.getValues().get(0)); @@ -68,7 +68,7 @@ public void setWithMoreThan50CharsIsRemoved() { @Test public void setWithLessThanOneCharIsOrEmptyRemoved() { - SplitFilterValidator.ValidationResult result = mValidator.cleanup(Arrays.asList("set1", "", " ")); + SplitFilterValidator.ValidationResult result = mValidator.cleanup("method", Arrays.asList("set1", "", " ")); assertEquals(1, result.getValues().size()); assertEquals("set1", result.getValues().get(0)); assertEquals(2, result.getInvalidValueCount()); @@ -76,7 +76,7 @@ public void setWithLessThanOneCharIsOrEmptyRemoved() { @Test public void nullSetIsRemoved() { - SplitFilterValidator.ValidationResult result = mValidator.cleanup(Arrays.asList("set1", null)); + SplitFilterValidator.ValidationResult result = mValidator.cleanup("method", Arrays.asList("set1", null)); assertEquals(1, result.getValues().size()); assertEquals("set1", result.getValues().get(0)); assertEquals(1, result.getInvalidValueCount()); @@ -84,7 +84,7 @@ public void nullSetIsRemoved() { @Test public void setWithExtraWhitespaceIsTrimmed() { - SplitFilterValidator.ValidationResult result = mValidator.cleanup(Arrays.asList("set1 ", " set2\r", "set3 ", "set 4\n")); + SplitFilterValidator.ValidationResult result = mValidator.cleanup("method", Arrays.asList("set1 ", " set2\r", "set3 ", "set 4\n")); assertEquals(3, result.getValues().size()); assertEquals("set1", result.getValues().get(0)); assertEquals("set2", result.getValues().get(1)); @@ -94,7 +94,7 @@ public void setWithExtraWhitespaceIsTrimmed() { @Test public void setsAreLowercase() { - SplitFilterValidator.ValidationResult result = mValidator.cleanup(Arrays.asList("SET1", "Set2", "SET_3")); + SplitFilterValidator.ValidationResult result = mValidator.cleanup("method", Arrays.asList("SET1", "Set2", "SET_3")); assertEquals(3, result.getValues().size()); assertEquals("set1", result.getValues().get(0)); assertEquals("set2", result.getValues().get(1));