18
18
import static com .google .firebase .remoteconfig .internal .Personalization .ANALYTICS_ORIGIN_PERSONALIZATION ;
19
19
import static com .google .firebase .remoteconfig .internal .Personalization .ANALYTICS_PULL_EVENT ;
20
20
import static com .google .firebase .remoteconfig .internal .Personalization .ANALYTICS_PULL_EVENT_INTERNAL ;
21
- import static com .google .firebase .remoteconfig .internal .Personalization .CHOICE_ID_KEY ;
21
+ import static com .google .firebase .remoteconfig .internal .Personalization .ARM_INDEX_LOG_KEY ;
22
+ import static com .google .firebase .remoteconfig .internal .Personalization .ARM_KEY ;
23
+ import static com .google .firebase .remoteconfig .internal .Personalization .ARM_VALUE ;
24
+ import static com .google .firebase .remoteconfig .internal .Personalization .CHOICE_ID_LOG_KEY ;
25
+ import static com .google .firebase .remoteconfig .internal .Personalization .GROUP ;
26
+ import static com .google .firebase .remoteconfig .internal .Personalization .PERSONALIZATION_ID_LOG_KEY ;
27
+ import static org .mockito .AdditionalMatchers .or ;
22
28
import static org .mockito .ArgumentMatchers .any ;
23
- import static org .mockito .ArgumentMatchers .anyString ;
24
29
import static org .mockito .ArgumentMatchers .eq ;
25
30
import static org .mockito .Mockito .doAnswer ;
26
31
import static org .mockito .Mockito .times ;
@@ -82,7 +87,10 @@ public void setUp() {
82
87
83
88
doAnswer (invocation -> FAKE_LOGS .add (invocation .getArgument (2 )))
84
89
.when (mockAnalyticsConnector )
85
- .logEvent (eq (ANALYTICS_ORIGIN_PERSONALIZATION ), anyString (), any (Bundle .class ));
90
+ .logEvent (
91
+ eq (ANALYTICS_ORIGIN_PERSONALIZATION ),
92
+ or (eq (ANALYTICS_PULL_EVENT ), eq (ANALYTICS_PULL_EVENT_INTERNAL )),
93
+ any (Bundle .class ));
86
94
87
95
personalization = new Personalization (mockAnalyticsConnector );
88
96
@@ -94,12 +102,15 @@ public void logArmActive_nonPersonalizationKey_notLogged() {
94
102
personalization .logArmActive ("key3" , CONFIG_CONTAINER );
95
103
96
104
verify (mockAnalyticsConnector , times (0 ))
97
- .logEvent (eq (ANALYTICS_ORIGIN_PERSONALIZATION ), anyString (), any (Bundle .class ));
105
+ .logEvent (
106
+ eq (ANALYTICS_ORIGIN_PERSONALIZATION ),
107
+ or (eq (ANALYTICS_PULL_EVENT ), eq (ANALYTICS_PULL_EVENT_INTERNAL )),
108
+ any (Bundle .class ));
98
109
assertThat (FAKE_LOGS ).isEmpty ();
99
110
}
100
111
101
112
@ Test
102
- public void logArmActive_singlePersonalizationKey_loggedOnce () {
113
+ public void logArmActive_singlePersonalizationKey_loggedInternallyAndExternally () {
103
114
personalization .logArmActive ("key1" , CONFIG_CONTAINER );
104
115
105
116
verify (mockAnalyticsConnector , times (1 ))
@@ -112,15 +123,24 @@ public void logArmActive_singlePersonalizationKey_loggedOnce() {
112
123
any (Bundle .class ));
113
124
assertThat (FAKE_LOGS ).hasSize (2 );
114
125
115
- Bundle params = new Bundle ();
116
- params .putString (CHOICE_ID_KEY , "id1" );
117
- assertThat (FAKE_LOGS ).comparingElementsUsing (TO_STRING ).contains (params .toString ());
126
+ Bundle logParams = new Bundle ();
127
+ logParams .putString (ARM_KEY , "key1" );
128
+ logParams .putString (ARM_VALUE , "value1" );
129
+ logParams .putString (PERSONALIZATION_ID_LOG_KEY , "p13n1" );
130
+ logParams .putInt (ARM_INDEX_LOG_KEY , 0 );
131
+ logParams .putString (GROUP , "BASELINE" );
132
+ Bundle internalLogParams = new Bundle ();
133
+ internalLogParams .putString (CHOICE_ID_LOG_KEY , "id1" );
134
+ assertThat (FAKE_LOGS )
135
+ .comparingElementsUsing (TO_STRING )
136
+ .containsExactly (logParams .toString (), internalLogParams .toString ());
118
137
}
119
138
120
139
@ Test
121
140
public void logArmActive_multiplePersonalizationKeys_loggedMultiple () {
122
141
personalization .logArmActive ("key1" , CONFIG_CONTAINER );
123
142
personalization .logArmActive ("key2" , CONFIG_CONTAINER );
143
+ personalization .logArmActive ("key1" , CONFIG_CONTAINER );
124
144
125
145
verify (mockAnalyticsConnector , times (2 ))
126
146
.logEvent (
@@ -132,13 +152,30 @@ public void logArmActive_multiplePersonalizationKeys_loggedMultiple() {
132
152
any (Bundle .class ));
133
153
assertThat (FAKE_LOGS ).hasSize (4 );
134
154
135
- Bundle params1 = new Bundle ();
136
- params1 .putString (CHOICE_ID_KEY , "id1" );
137
- Bundle params2 = new Bundle ();
138
- params2 .putString (CHOICE_ID_KEY , "id2" );
155
+ Bundle logParams1 = new Bundle ();
156
+ logParams1 .putString (ARM_KEY , "key1" );
157
+ logParams1 .putString (ARM_VALUE , "value1" );
158
+ logParams1 .putString (PERSONALIZATION_ID_LOG_KEY , "p13n1" );
159
+ logParams1 .putInt (ARM_INDEX_LOG_KEY , 0 );
160
+ logParams1 .putString (GROUP , "BASELINE" );
161
+ Bundle logParams2 = new Bundle ();
162
+ logParams2 .putString (ARM_KEY , "key2" );
163
+ logParams2 .putString (ARM_VALUE , "value2" );
164
+ logParams2 .putString (PERSONALIZATION_ID_LOG_KEY , "p13n2" );
165
+ logParams2 .putInt (ARM_INDEX_LOG_KEY , 1 );
166
+ logParams2 .putString (GROUP , "P13N" );
167
+ assertThat (FAKE_LOGS )
168
+ .comparingElementsUsing (TO_STRING )
169
+ .containsAtLeast (logParams1 .toString (), logParams2 .toString ())
170
+ .inOrder ();
171
+
172
+ Bundle internalLogParams1 = new Bundle ();
173
+ internalLogParams1 .putString (CHOICE_ID_LOG_KEY , "id1" );
174
+ Bundle internalLogParams2 = new Bundle ();
175
+ internalLogParams2 .putString (CHOICE_ID_LOG_KEY , "id2" );
139
176
assertThat (FAKE_LOGS )
140
177
.comparingElementsUsing (TO_STRING )
141
- .containsAtLeast (params1 .toString (), params2 .toString ())
178
+ .containsAtLeast (internalLogParams1 .toString (), internalLogParams2 .toString ())
142
179
.inOrder ();
143
180
}
144
181
}
0 commit comments