|
94 | 94 | import org.robolectric.annotation.Config;
|
95 | 95 | import org.robolectric.shadows.ShadowAlertDialog;
|
96 | 96 | import org.robolectric.shadows.ShadowLog;
|
97 |
| -import org.robolectric.shadows.ShadowSystemClock; |
98 | 97 |
|
99 | 98 | import java.lang.reflect.Field;
|
100 | 99 | import java.math.BigInteger;
|
|
107 | 106 | import static com.onesignal.OneSignalPackagePrivateHelper.NotificationOpenedProcessor_processFromContext;
|
108 | 107 | import static com.onesignal.OneSignalPackagePrivateHelper.NotificationSummaryManager_updateSummaryNotificationAfterChildRemoved;
|
109 | 108 | import static com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle;
|
| 109 | +import static com.onesignal.ShadowRoboNotificationManager.getNotificationsInGroup; |
110 | 110 | import static com.test.onesignal.RestClientAsserts.assertReportReceivedAtIndex;
|
111 | 111 | import static com.test.onesignal.RestClientAsserts.assertRestCalls;
|
112 | 112 | import static com.test.onesignal.TestHelpers.advanceSystemTimeBy;
|
@@ -327,51 +327,26 @@ public void shouldCancelAllNotificationsPartOfAGroup() throws Exception {
|
327 | 327 |
|
328 | 328 | @Test
|
329 | 329 | @Config(sdk = Build.VERSION_CODES.N)
|
330 |
| - public void testGetMostRecentNotifIdFromGroup() throws Exception { |
331 |
| - OneSignal.setInFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification); |
332 |
| - OneSignal.init(blankActivity, "123456789", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba"); |
| 330 | + public void testFourNotificationsUseProvidedGroup() throws Exception { |
| 331 | + OneSignal.init(blankActivity.getApplicationContext(), "123456789", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba"); |
333 | 332 | threadAndTaskWait();
|
334 | 333 |
|
335 | 334 | // Add 4 grouped notifications
|
336 | 335 | postNotificationWithOptionalGroup(4, "test1");
|
337 | 336 |
|
338 |
| - SQLiteDatabase readableDb = OneSignalDbHelper.getInstance(blankActivity).getReadableDatabase(); |
339 |
| - // Grab the most recent timestamped notification from local DB |
340 |
| - Integer mostRecentId = OneSignalNotificationManagerPackageHelper.getMostRecentNotifIdFromGroup(readableDb, "test1", false); |
341 |
| - |
342 |
| - Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications; |
343 |
| - // Iterator is ordered by notification post (0 index is most recent) |
344 |
| - Iterator<Map.Entry<Integer, PostedNotification>> postedNotifsIterator = postedNotifs.entrySet().iterator(); |
345 |
| - // First notification is the summary so we skip it and move on to the first normal notif |
346 |
| - postedNotifsIterator.next(); |
347 |
| - Integer expectedId = postedNotifsIterator.next().getKey(); |
348 |
| - |
349 |
| - // Assert our id equals the first real notif id (most recent posted) |
350 |
| - assertEquals(expectedId, mostRecentId); |
| 337 | + assertEquals(4, getNotificationsInGroup("test1").size()); |
351 | 338 | }
|
352 | 339 |
|
353 | 340 | @Test
|
354 | 341 | @Config(sdk = Build.VERSION_CODES.N)
|
355 |
| - public void testGetMostRecentNotifIdFromGroupless() throws Exception { |
356 |
| - OneSignal.setInFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification); |
357 |
| - OneSignal.init(blankActivity, "123456789", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba"); |
| 342 | + public void testFourGrouplessNotificationsUseDefaultGroup() throws Exception { |
| 343 | + OneSignal.init(blankActivity.getApplicationContext(), "123456789", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba"); |
358 | 344 | threadAndTaskWait();
|
359 | 345 |
|
360 | 346 | // Add 4 groupless notifications
|
361 | 347 | postNotificationWithOptionalGroup(4, null);
|
362 | 348 |
|
363 |
| - SQLiteDatabase readableDb = OneSignalDbHelper.getInstance(blankActivity).getReadableDatabase(); |
364 |
| - // Grab the most recent timestamped notification from local DB |
365 |
| - Integer mostRecentId = OneSignalNotificationManagerPackageHelper.getMostRecentNotifIdFromGroup(readableDb, null, true); |
366 |
| - |
367 |
| - Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications; |
368 |
| - // Iterator is ordered by notification post (0 index is most recent) |
369 |
| - Iterator<Map.Entry<Integer, PostedNotification>> postedNotifsIterator = postedNotifs.entrySet().iterator(); |
370 |
| - // Grab first active notification since groupless won't have a summary |
371 |
| - Integer expectedId = postedNotifsIterator.next().getKey(); |
372 |
| - |
373 |
| - // Assert our id equals the first real notif id (most recent posted) |
374 |
| - assertEquals(expectedId, mostRecentId); |
| 349 | + assertEquals(4, getNotificationsInGroup("os_group_undefined").size()); |
375 | 350 | }
|
376 | 351 |
|
377 | 352 | @Test
|
@@ -526,13 +501,11 @@ public void testGrouplessSummaryKeyReassignmentAtFourOrMoreNotification() throws
|
526 | 501 | assertEquals(0, groupCount);
|
527 | 502 | }
|
528 | 503 |
|
529 |
| - public Bundle postNotificationWithOptionalGroup(int notifCount, String group) { |
| 504 | + private @Nullable Bundle postNotificationWithOptionalGroup(int notifCount, @Nullable String group) { |
530 | 505 | Bundle bundle = null;
|
531 | 506 | for (int i = 0; i < notifCount; i++) {
|
532 | 507 | bundle = getBaseNotifBundle("UUID" + i);
|
533 |
| - |
534 |
| - if (group != null) |
535 |
| - bundle.putString("grp", group); |
| 508 | + bundle.putString("grp", group); |
536 | 509 |
|
537 | 510 | NotificationBundleProcessor_ProcessFromGCMIntentService(blankActivity, bundle, null);
|
538 | 511 | }
|
|
0 commit comments