@@ -149,8 +149,12 @@ public final class FirebaseRemoteConfigTest {
149
149
@ Mock private ConfigAutoFetch mockConfigAutoFetch ;
150
150
@ Mock private ConfigUpdateListenerRegistration mockRealtimeRegistration ;
151
151
@ Mock private HttpURLConnection mockHttpURLConnection ;
152
- @ Mock private ConfigUpdateListener mockListener ;
153
152
@ Mock private ConfigUpdateListener mockRetryListener ;
153
+ @ Mock private ConfigUpdateListener mockOnEventListener ;
154
+ @ Mock private ConfigUpdateListener mockStreamErrorEventListener ;
155
+ @ Mock private ConfigUpdateListener mockInvalidMessageEventListener ;
156
+ @ Mock private ConfigUpdateListener mockNotFetchedEventListener ;
157
+ @ Mock private ConfigUpdateListener mockUnavailableEventListener ;
154
158
155
159
@ Mock private ConfigCacheClient mockFireperfFetchedCache ;
156
160
@ Mock private ConfigCacheClient mockFireperfActivatedCache ;
@@ -274,7 +278,31 @@ public void setUp() throws Exception {
274
278
realtimeFetchedContainerResponse =
275
279
FetchResponse .forBackendUpdatesFetched (realtimeFetchedContainer , ETAG );
276
280
HashSet <ConfigUpdateListener > listeners = new HashSet ();
277
- listeners .add (mockListener );
281
+
282
+ ConfigUpdateListener listener =
283
+ new ConfigUpdateListener () {
284
+ @ Override
285
+ public void onEvent () {
286
+ mockOnEventListener .onEvent ();
287
+ }
288
+
289
+ @ Override
290
+ public void onError (@ NonNull FirebaseRemoteConfigException error ) {
291
+ if (error .getCode () == FirebaseRemoteConfigException .Code .CONFIG_UPDATE_STREAM_ERROR ) {
292
+ mockStreamErrorEventListener .onError (error );
293
+ } else if (error .getCode ()
294
+ == FirebaseRemoteConfigException .Code .CONFIG_UPDATE_MESSAGE_INVALID ) {
295
+ mockInvalidMessageEventListener .onError (error );
296
+ } else if (error .getCode ()
297
+ == FirebaseRemoteConfigException .Code .CONFIG_UPDATE_NOT_FETCHED ) {
298
+ mockNotFetchedEventListener .onError (error );
299
+ } else {
300
+ mockUnavailableEventListener .onError (error );
301
+ }
302
+ }
303
+ };
304
+
305
+ listeners .add (listener );
278
306
configAutoFetch =
279
307
new ConfigAutoFetch (mockHttpURLConnection , mockFetchHandler , listeners , mockRetryListener );
280
308
configRealtimeHttpClient =
@@ -1139,7 +1167,7 @@ public void realtime_stream_listen_fail() throws Exception {
1139
1167
when (mockHttpURLConnection .getInputStream ()).thenThrow (IOException .class );
1140
1168
configAutoFetch .listenForNotifications ();
1141
1169
1142
- verify (mockListener ).onError (any (FirebaseRemoteConfigClientException .class ));
1170
+ verify (mockInvalidMessageEventListener ).onError (any (FirebaseRemoteConfigClientException .class ));
1143
1171
}
1144
1172
1145
1173
@ Test
@@ -1149,8 +1177,10 @@ public void realtime_redirectStatusCode_noRetries() throws Exception {
1149
1177
doNothing ().when (configRealtimeHttpClientSpy ).closeRealtimeHttpStream ();
1150
1178
when (mockHttpURLConnection .getResponseCode ()).thenReturn (301 );
1151
1179
configRealtimeHttpClientSpy .beginRealtimeHttpStream ();
1180
+
1152
1181
verify (configRealtimeHttpClientSpy , never ()).startAutoFetch (any ());
1153
1182
verify (configRealtimeHttpClientSpy , never ()).retryHTTPConnection ();
1183
+ verify (mockStreamErrorEventListener ).onError (any (FirebaseRemoteConfigServerException .class ));
1154
1184
}
1155
1185
1156
1186
@ Test
@@ -1218,7 +1248,8 @@ public void realtime_stream_listen_and_failsafe_disabled() throws Exception {
1218
1248
when (mockFetchHandler .fetch (0 )).thenReturn (Tasks .forResult (realtimeFetchedContainerResponse ));
1219
1249
configAutoFetch .listenForNotifications ();
1220
1250
1221
- verify (mockListener , never ()).onError (any (FirebaseRemoteConfigServerException .class ));
1251
+ verify (mockUnavailableEventListener , never ())
1252
+ .onError (any (FirebaseRemoteConfigServerException .class ));
1222
1253
verify (mockFetchHandler ).getTemplateVersionNumber ();
1223
1254
}
1224
1255
@@ -1230,7 +1261,7 @@ public void realtime_stream_listen_get_inputstream_fail() throws Exception {
1230
1261
when (mockFetchHandler .fetch (0 )).thenReturn (Tasks .forResult (realtimeFetchedContainerResponse ));
1231
1262
configAutoFetch .listenForNotifications ();
1232
1263
1233
- verify (mockListener ).onError (any (FirebaseRemoteConfigClientException .class ));
1264
+ verify (mockInvalidMessageEventListener ).onError (any (FirebaseRemoteConfigClientException .class ));
1234
1265
}
1235
1266
1236
1267
@ Test
@@ -1239,7 +1270,7 @@ public void realtime_stream_autofetch_success() {
1239
1270
when (mockFetchHandler .fetch (0 )).thenReturn (Tasks .forResult (realtimeFetchedContainerResponse ));
1240
1271
configAutoFetch .fetchLatestConfig (1 , 1 );
1241
1272
1242
- verify (mockListener ).onEvent ();
1273
+ verify (mockOnEventListener ).onEvent ();
1243
1274
}
1244
1275
1245
1276
@ Test
@@ -1248,7 +1279,7 @@ public void realtime_stream_autofetch_failure() {
1248
1279
when (mockFetchHandler .fetch (0 )).thenReturn (Tasks .forResult (realtimeFetchedContainerResponse ));
1249
1280
configAutoFetch .fetchLatestConfig (1 , 1000 );
1250
1281
1251
- verify (mockListener ).onError (any (FirebaseRemoteConfigServerException .class ));
1282
+ verify (mockNotFetchedEventListener ).onError (any (FirebaseRemoteConfigServerException .class ));
1252
1283
}
1253
1284
1254
1285
private static void loadCacheWithConfig (
0 commit comments