Skip to content

Commit

Permalink
Add trackImpressions to SplitView
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Dec 12, 2024
1 parent 00d4dd4 commit b7f636b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
19 changes: 10 additions & 9 deletions src/main/java/io/split/android/client/SplitManagerImpl.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> treatments = new HashSet<>();
for (ParsedCondition condition : parsedSplit.parsedConditions()) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/split/android/client/api/SplitView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public class SplitView {
@NonNull
public List<String> sets = new ArrayList<>();
public String defaultTreatment;
public boolean trackImpressions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public Set<String> sets() {
return mSets;
}

public boolean trackImpression() {
public boolean trackImpressions() {
return mTrackImpressions;
}

Expand Down Expand Up @@ -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;

}
}
14 changes: 14 additions & 0 deletions src/test/java/io/split/android/client/SplitManagerImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b7f636b

Please sign in to comment.