From b7f636b6465e85b9e8c26205f989d348fecee777 Mon Sep 17 00:00:00 2001 From: Gaston Thea Date: Thu, 12 Dec 2024 15:09:06 -0300 Subject: [PATCH] Add trackImpressions to SplitView --- .../android/client/SplitManagerImpl.java | 19 ++++++++++--------- .../split/android/client/api/SplitView.java | 1 + .../engine/experiments/ParsedSplit.java | 4 ++-- .../android/client/SplitManagerImplTest.java | 14 ++++++++++++++ .../engine/experiments/SplitParserTest.java | 4 ++-- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/split/android/client/SplitManagerImpl.java b/src/main/java/io/split/android/client/SplitManagerImpl.java index 5fe90cd85..4f7bc30ae 100644 --- a/src/main/java/io/split/android/client/SplitManagerImpl.java +++ b/src/main/java/io/split/android/client/SplitManagerImpl.java @@ -1,5 +1,14 @@ package io.split.android.client; +import static io.split.android.client.utils.Utils.checkNotNull; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + import io.split.android.client.api.SplitView; import io.split.android.client.dtos.Partition; import io.split.android.client.dtos.Split; @@ -13,15 +22,6 @@ import io.split.android.engine.experiments.ParsedSplit; import io.split.android.engine.experiments.SplitParser; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static io.split.android.client.utils.Utils.checkNotNull; - public class SplitManagerImpl implements SplitManager { private final SplitsStorage _splitsStorage; @@ -144,6 +144,7 @@ private SplitView toSplitView(ParsedSplit parsedSplit) { splitView.configs = parsedSplit.configurations(); splitView.sets = new ArrayList<>(parsedSplit.sets() == null ? new HashSet<>() : parsedSplit.sets()); splitView.defaultTreatment = parsedSplit.defaultTreatment(); + splitView.trackImpressions = parsedSplit.trackImpressions(); Set treatments = new HashSet<>(); for (ParsedCondition condition : parsedSplit.parsedConditions()) { diff --git a/src/main/java/io/split/android/client/api/SplitView.java b/src/main/java/io/split/android/client/api/SplitView.java index 9cbc7192e..a8a416037 100644 --- a/src/main/java/io/split/android/client/api/SplitView.java +++ b/src/main/java/io/split/android/client/api/SplitView.java @@ -21,4 +21,5 @@ public class SplitView { @NonNull public List sets = new ArrayList<>(); public String defaultTreatment; + public boolean trackImpressions; } diff --git a/src/main/java/io/split/android/engine/experiments/ParsedSplit.java b/src/main/java/io/split/android/engine/experiments/ParsedSplit.java index a9ae822f7..eec6ed718 100644 --- a/src/main/java/io/split/android/engine/experiments/ParsedSplit.java +++ b/src/main/java/io/split/android/engine/experiments/ParsedSplit.java @@ -107,7 +107,7 @@ public Set sets() { return mSets; } - public boolean trackImpression() { + public boolean trackImpressions() { return mTrackImpressions; } @@ -155,7 +155,7 @@ public String toString() { ", default treatment:" + mDefaultTreatment + ", parsedConditions:" + mParsedCondition + ", trafficTypeName:" + mTrafficTypeName + ", changeNumber:" + mChangeNumber + - ", algo:" + mAlgo + ", config:" + mConfigurations + ", sets:" + mSets + ", trackImpression:" + mTrackImpressions; + ", algo:" + mAlgo + ", config:" + mConfigurations + ", sets:" + mSets + ", trackImpressions:" + mTrackImpressions; } } diff --git a/src/test/java/io/split/android/client/SplitManagerImplTest.java b/src/test/java/io/split/android/client/SplitManagerImplTest.java index 07adcfc84..02ff0b7f3 100644 --- a/src/test/java/io/split/android/client/SplitManagerImplTest.java +++ b/src/test/java/io/split/android/client/SplitManagerImplTest.java @@ -6,6 +6,7 @@ import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.core.IsNull.notNullValue; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.when; @@ -186,6 +187,19 @@ public void defaultTreatmentIsPresentWhenFetchingMultipleSplits() { assertEquals("some_treatment", splitNames.get(0).defaultTreatment); } + @Test + public void trackImpressionsIsPresent() { + Split split = SplitHelper.createSplit("FeatureName", 123, true, + "some_treatment", Arrays.asList(getTestCondition()), + "traffic", 456L, 1, null); + split.trackImpressions = false; + when(mSplitsStorage.get("FeatureName")).thenReturn(split); + + SplitView featureFlag = mSplitManager.split("FeatureName"); + + assertFalse(featureFlag.trackImpressions); + } + private Condition getTestCondition() { return SplitHelper.createCondition(CombiningMatcher.of(new AllKeysMatcher()), Arrays.asList(ConditionsTestUtil.partition("off", 10))); } diff --git a/src/test/java/io/split/android/engine/experiments/SplitParserTest.java b/src/test/java/io/split/android/engine/experiments/SplitParserTest.java index cf24758e2..ae7024f8d 100644 --- a/src/test/java/io/split/android/engine/experiments/SplitParserTest.java +++ b/src/test/java/io/split/android/engine/experiments/SplitParserTest.java @@ -509,8 +509,8 @@ public void trackImpressionsParsingTest(){ ParsedSplit actual = parser.parse(split); ParsedSplit actual2 = parser.parse(split2); - assertFalse(actual.trackImpression()); - assertTrue(actual2.trackImpression()); + assertFalse(actual.trackImpressions()); + assertTrue(actual2.trackImpressions()); } private void set_matcher_test(Condition c, io.split.android.engine.matchers.Matcher m) {