@@ -761,17 +761,19 @@ public void shouldSetBadgesWhenRestoringNotifications() throws Exception {
761
761
}
762
762
763
763
@ Test
764
- public void shouldNotShowNotificationWhenAlertIsBlankOrNull () {
764
+ public void shouldNotShowNotificationWhenAlertIsBlankOrNull () throws Exception {
765
765
Bundle bundle = getBaseNotifBundle ();
766
766
bundle .remove ("alert" );
767
767
NotificationBundleProcessor_ProcessFromFCMIntentService (blankActivity , bundle );
768
-
768
+ threadAndTaskWait ();
769
+
769
770
assertNoNotifications ();
770
771
771
772
bundle = getBaseNotifBundle ("UUID2" );
772
773
bundle .putString ("alert" , "" );
773
774
NotificationBundleProcessor_ProcessFromFCMIntentService (blankActivity , bundle );
774
-
775
+ threadAndTaskWait ();
776
+
775
777
assertNoNotifications ();
776
778
777
779
assertNotificationDbRecords (2 );
@@ -790,11 +792,13 @@ public void shouldUpdateNormalNotificationDisplayWhenReplacingANotification() th
790
792
bundle .putString ("grp" , "test1" );
791
793
bundle .putString ("collapse_key" , "1" );
792
794
NotificationBundleProcessor_ProcessFromFCMIntentService (blankActivity , bundle );
793
-
795
+ threadAndTaskWait ();
796
+
794
797
bundle = getBaseNotifBundle ("UUID2" );
795
798
bundle .putString ("grp" , "test1" );
796
799
bundle .putString ("collapse_key" , "1" );
797
800
NotificationBundleProcessor_ProcessFromFCMIntentService (blankActivity , bundle );
801
+ threadAndTaskWait ();
798
802
799
803
// Test - Summary created and sub notification. Summary will look the same as the normal notification.
800
804
Map <Integer , PostedNotification > postedNotifs = ShadowRoboNotificationManager .notifications ;
@@ -829,6 +833,8 @@ public void shouldHandleBasicNotifications() throws Exception {
829
833
// Make sure the notification got posted and the content is correct.
830
834
Bundle bundle = getBaseNotifBundle ();
831
835
NotificationBundleProcessor_ProcessFromFCMIntentService (blankActivity , bundle );
836
+ threadAndTaskWait ();
837
+
832
838
assertEquals (notifMessage , ShadowRoboNotificationManager .getLastShadowNotif ().getContentText ());
833
839
assertEquals (1 , ShadowBadgeCountUpdater .lastCount );
834
840
@@ -852,6 +858,8 @@ public void shouldHandleBasicNotifications() throws Exception {
852
858
853
859
// Should not display a duplicate notification, count should still be 1
854
860
NotificationBundleProcessor_ProcessFromFCMIntentService (blankActivity , bundle );
861
+ threadAndTaskWait ();
862
+
855
863
readableDb = dbHelper .getSQLiteDatabaseWithRetries ();
856
864
cursor = readableDb .query (NotificationTable .TABLE_NAME , null , null , null , null , null , null );
857
865
assertEquals (1 , cursor .getCount ());
@@ -861,6 +869,7 @@ public void shouldHandleBasicNotifications() throws Exception {
861
869
// Display a second notification
862
870
bundle = getBaseNotifBundle ("UUID2" );
863
871
NotificationBundleProcessor_ProcessFromFCMIntentService (blankActivity , bundle );
872
+ threadAndTaskWait ();
864
873
865
874
// Go forward 4 weeks
866
875
// Note: Does not effect the SQL function strftime
@@ -876,6 +885,8 @@ public void shouldHandleBasicNotifications() throws Exception {
876
885
// First opened should of been cleaned up, 1 week old non opened notification should stay, and one new record.
877
886
bundle = getBaseNotifBundle ("UUID3" );
878
887
NotificationBundleProcessor_ProcessFromFCMIntentService (blankActivity , bundle );
888
+ threadAndTaskWait ();
889
+
879
890
readableDb = dbHelper .getSQLiteDatabaseWithRetries ();
880
891
cursor = readableDb .query (NotificationTable .TABLE_NAME , new String [] { }, null , null , null , null , null );
881
892
@@ -1317,11 +1328,13 @@ private void setupNotificationExtensionServiceOverridePropertiesWithSummary() th
1317
1328
// 3. Post 2 notifications with the same grp key so a summary is generated
1318
1329
Bundle bundle = getBaseNotifBundle ("UUID1" );
1319
1330
bundle .putString ("grp" , "test1" );
1331
+
1320
1332
FCMBroadcastReceiver_processBundle (blankActivity , bundle );
1321
1333
threadAndTaskWait ();
1322
1334
1323
1335
bundle = getBaseNotifBundle ("UUID2" );
1324
1336
bundle .putString ("grp" , "test1" );
1337
+
1325
1338
FCMBroadcastReceiver_processBundle (blankActivity , bundle );
1326
1339
threadAndTaskWait ();
1327
1340
@@ -1389,10 +1402,23 @@ public void testRemoteNotificationReceivedHandler_notificationProcessingProperti
1389
1402
OneSignal .initWithContext (ApplicationProvider .getApplicationContext ());
1390
1403
OneSignal_setupNotificationServiceExtension ();
1391
1404
1392
- // 3. Test that WorkManager begins processing the notification
1393
- boolean ret = FCMBroadcastReceiver_processBundle (blankActivity , getBaseNotifBundle ());
1394
- threadAndTaskWait ();
1395
- assertTrue (ret );
1405
+ final boolean [] callbackEnded = {false };
1406
+ OneSignalPackagePrivateHelper .ProcessBundleReceiverCallback processBundleReceiverCallback = new OneSignalPackagePrivateHelper .ProcessBundleReceiverCallback () {
1407
+ public void onBundleProcessed (OneSignalPackagePrivateHelper .ProcessedBundleResult processedResult ) {
1408
+ assertNotNull (processedResult );
1409
+ // 3. Test that WorkManager begins processing the notification
1410
+ assertTrue (processedResult .isProcessed ());
1411
+ callbackEnded [0 ] = true ;
1412
+ }
1413
+ };
1414
+
1415
+ FCMBroadcastReceiver_processBundle (blankActivity , getBaseNotifBundle (), processBundleReceiverCallback );
1416
+ Awaitility .await ()
1417
+ .atMost (new Duration (3 , TimeUnit .SECONDS ))
1418
+ .pollInterval (new Duration (100 , TimeUnit .MILLISECONDS ))
1419
+ .untilAsserted (() -> {
1420
+ assertTrue (callbackEnded [0 ]);
1421
+ });
1396
1422
1397
1423
// 4. Receive a notification with all data fields used
1398
1424
FCMBroadcastReceiver_processBundle (blankActivity , getBundleWithAllOptionsSet ());
@@ -2132,10 +2158,24 @@ public void testNotificationReceived_duplicatesInShortTime() throws Exception {
2132
2158
blankActivityController .resume ();
2133
2159
threadAndTaskWait ();
2134
2160
2161
+ final boolean [] callbackEnded = {false };
2162
+ OneSignalPackagePrivateHelper .ProcessBundleReceiverCallback processBundleReceiverCallback = new OneSignalPackagePrivateHelper .ProcessBundleReceiverCallback () {
2163
+ public void onBundleProcessed (OneSignalPackagePrivateHelper .ProcessedBundleResult processedResult ) {
2164
+ assertNotNull (processedResult );
2165
+ assertTrue (processedResult .isProcessed ());
2166
+ callbackEnded [0 ] = true ;
2167
+ }
2168
+ };
2169
+
2135
2170
Bundle bundle = getBaseNotifBundle ();
2136
- boolean processResult = FCMBroadcastReceiver_processBundle (blankActivity , bundle );
2171
+ FCMBroadcastReceiver_processBundle (blankActivity , bundle , processBundleReceiverCallback );
2172
+ Awaitility .await ()
2173
+ .atMost (new Duration (3 , TimeUnit .SECONDS ))
2174
+ .pollInterval (new Duration (100 , TimeUnit .MILLISECONDS ))
2175
+ .untilAsserted (() -> {
2176
+ assertTrue (callbackEnded [0 ]);
2177
+ });
2137
2178
2138
- assertTrue (processResult );
2139
2179
assertNull (lastNotificationOpenedBody );
2140
2180
2141
2181
assertEquals ("Robo test message" , notificationReceivedBody );
@@ -2146,6 +2186,7 @@ public void testNotificationReceived_duplicatesInShortTime() throws Exception {
2146
2186
notificationReceivedBody = null ;
2147
2187
2148
2188
FCMBroadcastReceiver_processBundle (blankActivity , bundle );
2189
+ threadAndTaskWait ();
2149
2190
2150
2191
assertNull (lastNotificationOpenedBody );
2151
2192
assertNull (notificationReceivedBody );
@@ -2156,6 +2197,7 @@ public void testNotificationReceived_duplicatesInShortTime() throws Exception {
2156
2197
// Test that only NotificationReceivedHandler fires
2157
2198
bundle = getBaseNotifBundle ("UUID2" );
2158
2199
FCMBroadcastReceiver_processBundle (blankActivity , bundle );
2200
+ threadAndTaskWait ();
2159
2201
2160
2202
assertNull (lastNotificationOpenedBody );
2161
2203
assertEquals ("Robo test message" , notificationReceivedBody );
0 commit comments