Skip to content

Commit 4aa8c44

Browse files
committed
sending empty map in case when null is passed in attributes listener
1 parent c6bf1d8 commit 4aa8c44

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

core-api/src/main/java/com/optimizely/ab/notification/DecisionNotificationListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.optimizely.ab.notification;
1818

1919
import javax.annotation.Nonnull;
20+
import java.util.HashMap;
2021
import java.util.Map;
2122

2223
public abstract class DecisionNotificationListener implements NotificationListener, DecisionNotificationListenerInterface {
@@ -36,8 +37,9 @@ public final void notify(Object... args) {
3637
if (args[2] != null) {
3738
assert (args[2] instanceof java.util.Map);
3839
attributes = (Map<String, ?>) args[2];
40+
} else {
41+
attributes = new HashMap<>();
3942
}
40-
;
4143
assert (args[3] instanceof java.util.Map);
4244
Map<String, ?> decisionInfo = (Map<String, ?>) args[3];
4345
onDecision(type, userId, attributes, decisionInfo);

core-api/src/test/java/com/optimizely/ab/OptimizelyTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,7 @@ private DecisionNotificationListener getDecisionListener(final String testType,
26412641
public void onDecision(@Nonnull String type, @Nonnull String userId, @Nonnull Map<String, ?> attributes, @Nonnull Map<String, ?> decisionInfo) {
26422642
assertEquals(type, testType);
26432643
assertEquals(userId, testUserId);
2644+
assertEquals(attributes, testUserAttributes);
26442645
for (Map.Entry<String, ?> entry : attributes.entrySet()) {
26452646
assertEquals(testUserAttributes.get(entry.getKey()), entry.getValue());
26462647
}
@@ -2702,7 +2703,7 @@ public void getFeatureVariableWithListenerUserInExperimentFeatureOn() throws Exc
27022703
/**
27032704
* Verify that the {@link Optimizely#getFeatureVariableString(String, String, String, Map)}
27042705
* notification listener of getFeatureVariableString is called when feature is in experiment and feature enabled is false
2705-
* than default value will get returned
2706+
* than default value will get returned and passing null attribute will send empty map instead of null
27062707
*/
27072708
@Test
27082709
public void getFeatureVariableWithListenerUserInExperimentFeatureOff() {
@@ -2718,7 +2719,6 @@ public void getFeatureVariableWithListenerUserInExperimentFeatureOff() {
27182719
.build();
27192720

27202721
final Map<String, String> testUserAttributes = new HashMap<>();
2721-
testUserAttributes.put(ATTRIBUTE_HOUSE_KEY, AUDIENCE_GRYFFINDOR_VALUE);
27222722

27232723
final Map<String, Object> testDecisionInfoMap = new HashMap<>();
27242724
testDecisionInfoMap.put(DecisionInfoEnums.GetFeatureVariableDecisionInfo.SOURCE_EXPERIMENT_KEY.toString(), "multivariate_experiment");
@@ -2740,7 +2740,7 @@ public void getFeatureVariableWithListenerUserInExperimentFeatureOff() {
27402740
validFeatureKey,
27412741
validVariableKey,
27422742
userID,
2743-
Collections.singletonMap(ATTRIBUTE_HOUSE_KEY, AUDIENCE_GRYFFINDOR_VALUE)),
2743+
null),
27442744
expectedValue);
27452745

27462746
assertTrue(optimizely.notificationCenter.removeNotificationListener(notificationId));

0 commit comments

Comments
 (0)