@@ -199,14 +199,6 @@ public class MainOneSignalClassRunner {
199
199
private MockSessionManager sessionManager ;
200
200
private MockOneSignalDBHelper dbHelper ;
201
201
202
- private static String lastUserId , lastRegistrationId ;
203
- private static void getIdsAvailableHandler () {
204
- OneSignal .idsAvailable ((userId , registrationId ) -> {
205
- lastUserId = userId ;
206
- lastRegistrationId = registrationId ;
207
- });
208
- }
209
-
210
202
private static String lastNotificationOpenedBody ;
211
203
private static OneSignal .OSNotificationOpenedHandler getNotificationOpenedHandler () {
212
204
return openedResult -> {
@@ -227,8 +219,6 @@ private static void getGetTagsHandler() {
227
219
}
228
220
229
221
private static void cleanUp () throws Exception {
230
- lastUserId = lastRegistrationId = null ;
231
-
232
222
lastNotificationOpenedBody = null ;
233
223
lastGetTags = null ;
234
224
lastExternalUserIdResponse = null ;
@@ -908,8 +898,7 @@ public void testPutStillCalledOnChanges() throws Exception {
908
898
threadAndTaskWait ();
909
899
910
900
assertEquals (4 , ShadowOneSignalRestClient .networkCallCount );
911
- getIdsAvailableHandler ();
912
- assertEquals ("players/" + lastUserId , ShadowOneSignalRestClient .lastUrl );
901
+ assertEquals ("players/" + OneSignal .getDeviceState ().getUserId (), ShadowOneSignalRestClient .lastUrl );
913
902
assertEquals ("{\" carrier\" :\" test2\" ,\" app_id\" :\" b4f7f966-d8cc-11e4-bed1-df8f05be55ba\" }" , ShadowOneSignalRestClient .lastPost .toString ());
914
903
}
915
904
@@ -947,8 +936,7 @@ public void testOnSessionEvenIfQuickAppRestart() throws Exception {
947
936
948
937
// 4. Ensure we made 4 network calls. (2 to android_params and 1 create player call)
949
938
assertEquals (5 , ShadowOneSignalRestClient .networkCallCount );
950
- getIdsAvailableHandler ();
951
- assertEquals ("players/" + lastUserId + "/on_session" , ShadowOneSignalRestClient .lastUrl );
939
+ assertEquals ("players/" + OneSignal .getDeviceState ().getUserId () + "/on_session" , ShadowOneSignalRestClient .lastUrl );
952
940
assertEquals (REST_METHOD .POST , ShadowOneSignalRestClient .requests .get (4 ).method );
953
941
}
954
942
@@ -1244,7 +1232,6 @@ public void testUnsubscribeStatusShouldBeSetIfFCMErrored() throws Exception {
1244
1232
1245
1233
@ Test
1246
1234
public void testInvalidGoogleProjectNumberWithSuccessfulRegisterResponse () throws Exception {
1247
- getIdsAvailableHandler ();
1248
1235
// A more real test would be "missing support library" but bad project number is an easier setup
1249
1236
// and is testing the same logic.
1250
1237
ShadowPushRegistratorFCM .fail = true ;
@@ -1255,14 +1242,14 @@ public void testInvalidGoogleProjectNumberWithSuccessfulRegisterResponse() throw
1255
1242
1256
1243
assertEquals (-7 , ShadowOneSignalRestClient .lastPost .getInt ("notification_types" ));
1257
1244
// Test that idsAvailable still fires
1258
- assertEquals (ShadowOneSignalRestClient .pushUserId , lastUserId );
1259
- assertNull (lastRegistrationId ); // Since FCM registration failed, this should be null
1245
+ assertEquals (ShadowOneSignalRestClient .pushUserId , OneSignal . getDeviceState (). getUserId () );
1246
+ assertNull (OneSignal . getDeviceState (). getPushToken () ); // Since FCM registration failed, this should be null
1260
1247
1261
1248
// We now get a push token after the device registers with Onesignal,
1262
1249
// the idsAvailable callback should fire a 2nd time with a registrationId automatically
1263
1250
ShadowPushRegistratorFCM .manualFireRegisterForPush ();
1264
1251
threadAndTaskWait ();
1265
- assertEquals (ShadowPushRegistratorFCM .regId , lastRegistrationId );
1252
+ assertEquals (ShadowPushRegistratorFCM .regId , OneSignal . getDeviceState (). getPushToken () );
1266
1253
}
1267
1254
1268
1255
@ Test
@@ -1284,31 +1271,14 @@ public void testGMSErrorsAfterSuccessfulSubscribeDoNotUnsubscribeTheDevice() thr
1284
1271
public void testInvalidGoogleProjectNumberWithFailedRegisterResponse () throws Exception {
1285
1272
// Ensures lower number notification_types do not over right higher numbered ones.
1286
1273
ShadowPushRegistratorFCM .fail = true ;
1287
- getIdsAvailableHandler ();
1288
1274
// OneSignalInitWithBadProjectNum();
1289
1275
OneSignalInit ();
1290
1276
threadAndTaskWait ();
1291
1277
Robolectric .getForegroundThreadScheduler ().runOneTask ();
1292
1278
assertEquals (-7 , ShadowOneSignalRestClient .lastPost .getInt ("notification_types" ));
1293
1279
1294
1280
// Test that idsAvailable still fires
1295
- assertEquals (ShadowOneSignalRestClient .pushUserId , lastUserId );
1296
- }
1297
-
1298
- @ Test
1299
- public void testUnsubcribedShouldMakeRegIdNullToIdsAvailable () throws Exception {
1300
- getIdsAvailableHandler ();
1301
- OneSignalInit ();
1302
- threadAndTaskWait ();
1303
- assertEquals (ShadowPushRegistratorFCM .regId , ShadowOneSignalRestClient .lastPost .getString ("identifier" ));
1304
-
1305
- Robolectric .getForegroundThreadScheduler ().runOneTask ();
1306
- assertEquals (ShadowPushRegistratorFCM .regId , lastRegistrationId );
1307
-
1308
- OneSignal .disablePush (false );
1309
- getIdsAvailableHandler ();
1310
- threadAndTaskWait ();
1311
- assertNull (lastRegistrationId );
1281
+ assertEquals (ShadowOneSignalRestClient .pushUserId , OneSignal .getDeviceState ().getUserId ());
1312
1282
}
1313
1283
1314
1284
@ Test
@@ -1414,25 +1384,6 @@ public void shouldAllowMultipleSetSubscription() throws Exception {
1414
1384
assertNull (ShadowOneSignalRestClient .lastPost );
1415
1385
}
1416
1386
1417
- private static boolean userIdWasNull = false ;
1418
- @ Test
1419
- public void shouldNotFireIdsAvailableWithoutUserId () throws Exception {
1420
- ShadowOneSignalRestClient .failNext = true ;
1421
- ShadowPushRegistratorFCM .fail = true ;
1422
-
1423
- OneSignal .idsAvailable (new OneSignal .OSIdsAvailableHandler () {
1424
- @ Override
1425
- public void idsAvailable (String userId , String registrationId ) {
1426
- if (userId == null )
1427
- userIdWasNull = true ;
1428
- }
1429
- });
1430
-
1431
- OneSignalInit ();
1432
- assertFalse (userIdWasNull );
1433
- threadAndTaskWait ();
1434
- }
1435
-
1436
1387
@ Test
1437
1388
public void testFCMTimeOutThenSuccessesLater () throws Exception {
1438
1389
// Init with a bad connection to Google.
@@ -1939,7 +1890,6 @@ public void shouldSendTagsWithRequestBatching() throws Exception {
1939
1890
public void shouldNotAttemptToSendTagsBeforeGettingPlayerId () throws Exception {
1940
1891
ShadowPushRegistratorFCM .skipComplete = true ;
1941
1892
OneSignalInit ();
1942
- getIdsAvailableHandler ();
1943
1893
threadAndTaskWait ();
1944
1894
1945
1895
assertEquals (1 , ShadowOneSignalRestClient .networkCallCount );
@@ -1954,7 +1904,7 @@ public void shouldNotAttemptToSendTagsBeforeGettingPlayerId() throws Exception {
1954
1904
threadAndTaskWait ();
1955
1905
1956
1906
assertEquals (2 , ShadowOneSignalRestClient .networkCallCount );
1957
- assertNotNull (lastUserId );
1907
+ assertNotNull (OneSignal . getDeviceState (). getUserId () );
1958
1908
}
1959
1909
1960
1910
private static class TestChangeTagsUpdateHandler implements ChangeTagsUpdateHandler {
@@ -2224,24 +2174,10 @@ public void tagsAvailable(JSONObject tags) {
2224
2174
});
2225
2175
threadAndTaskWait ();
2226
2176
2227
- final AtomicBoolean callbackFired = new AtomicBoolean (false );
2228
- OneSignal .OSIdsAvailableHandler idsAvailableHandler = new OneSignal .OSIdsAvailableHandler () {
2229
- @ Override
2230
- public void idsAvailable (String userId , String registrationId ) {
2231
- //Assert the userId being returned
2232
- callbackFired .set (true );
2233
- assertEquals (ShadowOneSignalRestClient .pushUserId , userId );
2234
- }
2235
- };
2236
-
2237
- OneSignal .idsAvailable (idsAvailableHandler );
2238
- System .gc (); //make sure the IdsAvailableHandler is retained...
2239
-
2240
-
2241
2177
// ----- END QUEUE ------
2242
2178
2243
- //there should be 503 pending operations in the queue
2244
- assertEquals (503 , OneSignal_taskQueueWaitingForInit ().size ());
2179
+ // There should be 502 pending operations in the queue
2180
+ assertEquals (502 , OneSignal_taskQueueWaitingForInit ().size ());
2245
2181
2246
2182
OneSignalInit (); //starts the pending tasks executor
2247
2183
@@ -2283,7 +2219,6 @@ public void tagsAvailable(JSONObject tags) {
2283
2219
2284
2220
//Assert that the queued up operations ran in correct order
2285
2221
// and that the correct user state was POSTed and synced
2286
- assertTrue (callbackFired .get ()); //check if the callback got fired
2287
2222
2288
2223
//assert the hashed email which should be test1@test.com, NOT test@test.com
2289
2224
assertEquals ("94fba03762323f286d7c3ca9e001c541" , ShadowOneSignalRestClient .lastPost .getString ("em_m" ));
0 commit comments