Skip to content

Commit 8543718

Browse files
committed
Fix failing test
* Fix test testNotificationWillShowInForegroundHandler_notCallCompleteShowsNotificationAfterTimeout
1 parent dfd8111 commit 8543718

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationBundleProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private static void saveNotification(OSNotificationGenerationJob notificationJob
236236
values.put(NotificationTable.COLUMN_NAME_FULL_DATA, jsonPayload.toString());
237237

238238
dbHelper.insertOrThrow(NotificationTable.TABLE_NAME, null, values);
239-
239+
OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "Notification saved values: " + values.toString());
240240
if (!opened)
241241
BadgeCountUpdater.update(dbHelper, context);
242242
} catch (JSONException e) {

OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,8 +1996,9 @@ public void testNotificationWillShowInForegroundHandler_doesNotFireWhenAppBackgr
19961996
}
19971997

19981998
@Test
1999-
@Config(shadows = { ShadowGenerateNotification.class, ShadowTimeoutHandler.class })
1999+
@Config(shadows = { ShadowGenerateNotification.class, ShadowTimeoutHandler.class, ShadowNotificationReceivedEvent.class })
20002000
public void testNotificationWillShowInForegroundHandler_notCallCompleteShowsNotificationAfterTimeout() throws Exception {
2001+
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
20012002
// 1. Init OneSignal
20022003
OneSignal.setAppId("b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
20032004
OneSignal.initWithContext(blankActivity);
@@ -2022,8 +2023,16 @@ public void testNotificationWillShowInForegroundHandler_notCallCompleteShowsNoti
20222023
// 4. Make sure the callback counter is only fired once for App NotificationWillShowInForegroundHandler
20232024
assertEquals(1, callbackCounter);
20242025

2025-
// 5. Make sure 1 notification exists in DB
2026-
assertNotificationDbRecords(1);
2026+
// Complete being call from Notification Receiver Handler thread
2027+
Awaitility.await()
2028+
.atMost(new Duration(5, TimeUnit.SECONDS))
2029+
.pollInterval(new Duration(500, TimeUnit.MILLISECONDS))
2030+
.untilAsserted(() -> {
2031+
// 5. Make sure 1 notification exists in DB
2032+
assertNotificationDbRecords(1);
2033+
// 6. Notification not opened then badges should be 1
2034+
assertEquals(1, ShadowBadgeCountUpdater.lastCount);
2035+
});
20272036
}
20282037

20292038
@Test

0 commit comments

Comments
 (0)