Skip to content

Commit ff5b878

Browse files
committed
Nit fixes and checking if listener is getting called
1 parent 017b0d2 commit ff5b878

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919
public class DecisionInfoEnums {
2020
public enum FeatureVariableDecisionInfo {
21-
SOURCE_EXPERIMENT_KEY("source_experiment_key"),
22-
SOURCE_VARIATION_KEY("source_variation_key"),
2321
FEATURE_KEY("feature_key"),
2422
FEATURE_ENABLED("feature_enabled"),
23+
SOURCE("source"),
24+
SOURCE_EXPERIMENT_KEY("source_experiment_key"),
25+
SOURCE_VARIATION_KEY("source_variation_key"),
2526
VARIABLE_KEY("variable_key"),
2627
VARIABLE_TYPE("variable_type"),
27-
VARIABLE_VALUE("variable_value"),
28-
SOURCE("source");
28+
VARIABLE_VALUE("variable_value");
2929

3030
private final String key;
3131

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public interface DecisionNotificationListenerInterface {
2525
* onDecision called when an activate was triggered
2626
*
2727
* @param type - The notification type.
28-
* @param userId - The userId passed into activate.
29-
* @param attributes - The filtered attribute list passed into activate
28+
* @param userId - The userId passed to the API.
29+
* @param attributes - The attribute map passed to the API.
3030
* @param decisionInfo - The decision information containing all parameters passed in API.
3131
*/
3232
void onDecision(@Nonnull String type,

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,6 +2629,8 @@ public void getVariationWithInvalidDatafile() throws Exception {
26292629

26302630
//======== Notification listeners ========//
26312631

2632+
boolean isListenerCalled = false;
2633+
26322634
/**
26332635
* Helper method to return decisionListener
26342636
**/
@@ -2648,6 +2650,7 @@ public void onDecision(@Nonnull String type, @Nonnull String userId, @Nonnull Ma
26482650
for (Map.Entry<String, ?> entry : decisionInfo.entrySet()) {
26492651
assertEquals(testDecisionInfo.get(entry.getKey()), entry.getValue());
26502652
}
2653+
isListenerCalled = true;
26512654
}
26522655
};
26532656
}
@@ -2662,7 +2665,7 @@ public void onDecision(@Nonnull String type, @Nonnull String userId, @Nonnull Ma
26622665
@Test
26632666
public void getFeatureVariableWithListenerUserInExperimentFeatureOn() throws Exception {
26642667
assumeTrue(datafileVersion >= Integer.parseInt(ProjectConfig.Version.V4.toString()));
2665-
2668+
isListenerCalled = false;
26662669
final String validFeatureKey = FEATURE_MULTI_VARIATE_FEATURE_KEY;
26672670
String validVariableKey = VARIABLE_FIRST_LETTER_KEY;
26682671
String expectedValue = "F";
@@ -2697,6 +2700,9 @@ public void getFeatureVariableWithListenerUserInExperimentFeatureOn() throws Exc
26972700
Collections.singletonMap(ATTRIBUTE_HOUSE_KEY, AUDIENCE_GRYFFINDOR_VALUE)),
26982701
expectedValue);
26992702

2703+
// Verify that listener being called
2704+
assertTrue(isListenerCalled);
2705+
27002706
assertTrue(optimizely.notificationCenter.removeNotificationListener(notificationId));
27012707
}
27022708

@@ -2708,7 +2714,7 @@ public void getFeatureVariableWithListenerUserInExperimentFeatureOn() throws Exc
27082714
@Test
27092715
public void getFeatureVariableWithListenerUserInExperimentFeatureOff() {
27102716
assumeTrue(datafileVersion >= Integer.parseInt(ProjectConfig.Version.V4.toString()));
2711-
2717+
isListenerCalled = false;
27122718
final String validFeatureKey = FEATURE_MULTI_VARIATE_FEATURE_KEY;
27132719
String validVariableKey = VARIABLE_FIRST_LETTER_KEY;
27142720
String expectedValue = "H";
@@ -2743,6 +2749,9 @@ public void getFeatureVariableWithListenerUserInExperimentFeatureOff() {
27432749
null),
27442750
expectedValue);
27452751

2752+
// Verify that listener being called
2753+
assertTrue(isListenerCalled);
2754+
27462755
assertTrue(optimizely.notificationCenter.removeNotificationListener(notificationId));
27472756
}
27482757

@@ -2754,6 +2763,7 @@ public void getFeatureVariableWithListenerUserInExperimentFeatureOff() {
27542763
public void getFeatureVariableWithListenerUserInRollOutFeatureOn() throws Exception {
27552764
assumeTrue(datafileVersion >= Integer.parseInt(ProjectConfig.Version.V4.toString()));
27562765

2766+
isListenerCalled = false;
27572767
final String validFeatureKey = FEATURE_SINGLE_VARIABLE_STRING_KEY;
27582768
String validVariableKey = VARIABLE_STRING_VARIABLE_KEY;
27592769
String expectedValue = "lumos";
@@ -2788,6 +2798,9 @@ public void getFeatureVariableWithListenerUserInRollOutFeatureOn() throws Except
27882798
Collections.singletonMap(ATTRIBUTE_HOUSE_KEY, AUDIENCE_GRYFFINDOR_VALUE)),
27892799
expectedValue);
27902800

2801+
// Verify that listener being called
2802+
assertTrue(isListenerCalled);
2803+
27912804
assertTrue(optimizely.notificationCenter.removeNotificationListener(notificationId));
27922805
}
27932806

@@ -2799,6 +2812,7 @@ public void getFeatureVariableWithListenerUserInRollOutFeatureOn() throws Except
27992812
public void getFeatureVariableWithListenerUserNotInRollOutFeatureOff() {
28002813
assumeTrue(datafileVersion >= Integer.parseInt(ProjectConfig.Version.V4.toString()));
28012814

2815+
isListenerCalled = false;
28022816
final String validFeatureKey = FEATURE_SINGLE_VARIABLE_BOOLEAN_KEY;
28032817
String validVariableKey = VARIABLE_BOOLEAN_VARIABLE_KEY;
28042818
Boolean expectedValue = true;
@@ -2833,6 +2847,9 @@ public void getFeatureVariableWithListenerUserNotInRollOutFeatureOff() {
28332847
Collections.singletonMap(ATTRIBUTE_HOUSE_KEY, AUDIENCE_GRYFFINDOR_VALUE)),
28342848
expectedValue);
28352849

2850+
// Verify that listener being called
2851+
assertTrue(isListenerCalled);
2852+
28362853
assertTrue(optimizely.notificationCenter.removeNotificationListener(notificationId));
28372854
}
28382855

@@ -2844,6 +2861,7 @@ public void getFeatureVariableWithListenerUserNotInRollOutFeatureOff() {
28442861
public void getFeatureVariableIntegerWithListenerUserInRollOutFeatureOn() {
28452862
assumeTrue(datafileVersion >= Integer.parseInt(ProjectConfig.Version.V4.toString()));
28462863

2864+
isListenerCalled = false;
28472865
final String validFeatureKey = FEATURE_SINGLE_VARIABLE_INTEGER_KEY;
28482866
String validVariableKey = VARIABLE_INTEGER_VARIABLE_KEY;
28492867
int expectedValue = 7;
@@ -2877,6 +2895,9 @@ public void getFeatureVariableIntegerWithListenerUserInRollOutFeatureOn() {
28772895
Collections.singletonMap(ATTRIBUTE_HOUSE_KEY, AUDIENCE_GRYFFINDOR_VALUE)),
28782896
(long) expectedValue);
28792897

2898+
// Verify that listener being called
2899+
assertTrue(isListenerCalled);
2900+
28802901
assertTrue(optimizely.notificationCenter.removeNotificationListener(notificationId));
28812902
}
28822903

@@ -2888,6 +2909,7 @@ public void getFeatureVariableIntegerWithListenerUserInRollOutFeatureOn() {
28882909
public void getFeatureVariableDoubleWithListenerUserInExperimentFeatureOn() throws Exception {
28892910
assumeTrue(datafileVersion >= Integer.parseInt(ProjectConfig.Version.V4.toString()));
28902911

2912+
isListenerCalled = false;
28912913
final String validFeatureKey = FEATURE_SINGLE_VARIABLE_DOUBLE_KEY;
28922914
String validVariableKey = VARIABLE_DOUBLE_VARIABLE_KEY;
28932915

@@ -2921,6 +2943,9 @@ public void getFeatureVariableDoubleWithListenerUserInExperimentFeatureOn() thro
29212943
Collections.singletonMap(ATTRIBUTE_HOUSE_KEY, AUDIENCE_SLYTHERIN_VALUE)),
29222944
Math.PI, 2);
29232945

2946+
// Verify that listener being called
2947+
assertTrue(isListenerCalled);
2948+
29242949
assertTrue(optimizely.notificationCenter.removeNotificationListener(notificationId));
29252950
}
29262951

0 commit comments

Comments
 (0)