Search in sources :

Example 1 with GcmBroadcastReceiver_processBundle

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);
}
Also used : OneSignal(com.onesignal.OneSignal) ShadowOneSignal(com.onesignal.ShadowOneSignal) Bundle(android.os.Bundle) GcmBroadcastReceiver_processBundle(com.onesignal.OneSignalPackagePrivateHelper.GcmBroadcastReceiver_processBundle) GenerateNotificationRunner.getBaseNotifBundle(com.test.onesignal.GenerateNotificationRunner.getBaseNotifBundle) OSNotification(com.onesignal.OSNotification) Test(org.junit.Test)

Aggregations

Bundle (android.os.Bundle)1 OSNotification (com.onesignal.OSNotification)1 OneSignal (com.onesignal.OneSignal)1 GcmBroadcastReceiver_processBundle (com.onesignal.OneSignalPackagePrivateHelper.GcmBroadcastReceiver_processBundle)1 ShadowOneSignal (com.onesignal.ShadowOneSignal)1 GenerateNotificationRunner.getBaseNotifBundle (com.test.onesignal.GenerateNotificationRunner.getBaseNotifBundle)1 Test (org.junit.Test)1