use of com.onesignal.OneSignalPackagePrivateHelper.GcmBroadcastReceiver_processBundle in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method testNotificationReceivedWhenAppInFocus.
@Test
public void testNotificationReceivedWhenAppInFocus() throws Exception {
OneSignal.init(blankActivity, "123456789", ONESIGNAL_APP_ID, getNotificationOpenedHandler(), new OneSignal.NotificationReceivedHandler() {
@Override
public void notificationReceived(OSNotification notification) {
androidNotificationId = notification.androidNotificationId;
notificationReceivedBody = notification.payload.body;
}
});
threadAndTaskWait();
OneSignal.setInFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification);
Bundle bundle = getBaseNotifBundle();
boolean processResult = GcmBroadcastReceiver_processBundle(blankActivity, bundle);
threadAndTaskWait();
threadAndTaskWait();
Assert.assertEquals(null, notificationOpenedMessage);
Assert.assertFalse(processResult);
// NotificationBundleProcessor.Process(...) will be called if processResult is true as a service
NotificationBundleProcessor_Process(blankActivity, false, bundleAsJSONObject(bundle), null);
Assert.assertEquals("Robo test message", notificationReceivedBody);
Assert.assertFalse(0 == androidNotificationId);
// Don't fire for duplicates
notificationOpenedMessage = null;
notificationReceivedBody = null;
OneSignal.setInFocusDisplaying(OneSignal.OSInFocusDisplayOption.None);
Assert.assertNull(notificationOpenedMessage);
GcmBroadcastReceiver_processBundle(blankActivity, bundle);
threadAndTaskWait();
Assert.assertEquals(null, notificationOpenedMessage);
Assert.assertEquals(null, notificationReceivedBody);
// Test that only NotificationReceivedHandler fires
OneSignal.setInFocusDisplaying(OneSignal.OSInFocusDisplayOption.None);
bundle = getBaseNotifBundle("UUID2");
notificationOpenedMessage = null;
notificationReceivedBody = null;
GcmBroadcastReceiver_processBundle(blankActivity, bundle);
threadAndTaskWait();
threadAndTaskWait();
Assert.assertEquals(null, notificationOpenedMessage);
Assert.assertNull(notificationOpenedMessage);
Assert.assertEquals("Robo test message", notificationReceivedBody);
}
Aggregations