Search in sources :

Example 1 with FCMBroadcastReceiver_onReceived_withIntent

use of com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withIntent in project OneSignal-Android-SDK by OneSignal.

the class GenerateNotificationRunner method shouldSetButtonsCorrectly.

@Test
@Config(shadows = { ShadowFCMBroadcastReceiver.class, ShadowGenerateNotification.class })
public void shouldSetButtonsCorrectly() throws Exception {
    final Intent intent = new Intent();
    intent.setAction("com.google.android.c2dm.intent.RECEIVE");
    intent.putExtra("message_type", "gcm");
    Bundle bundle = getBaseNotifBundle();
    addButtonsToReceivedPayload(bundle);
    intent.putExtras(bundle);
    FCMBroadcastReceiver_onReceived_withIntent(blankActivity, intent);
    threadAndTaskWait();
    // Normal notifications should be generated right from the BroadcastReceiver
    // without creating a service.
    assertNull(Shadows.shadowOf(blankActivity).getNextStartedService());
    Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
    Iterator<Map.Entry<Integer, PostedNotification>> postedNotifsIterator = postedNotifs.entrySet().iterator();
    PostedNotification lastNotification = postedNotifsIterator.next().getValue();
    assertEquals(1, lastNotification.notif.actions.length);
    String json_data = shadowOf(lastNotification.notif.actions[0].actionIntent).getSavedIntent().getStringExtra(BUNDLE_KEY_ONESIGNAL_DATA);
    assertEquals("id1", new JSONObject(json_data).optString(BUNDLE_KEY_ACTION_ID));
}
Also used : BigInteger(java.math.BigInteger) JSONObject(org.json.JSONObject) Bundle(android.os.Bundle) FCMBroadcastReceiver_processBundle(com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_processBundle) OneSignalPackagePrivateHelper.createInternalPayloadBundle(com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle) FCMBroadcastReceiver_onReceived_withIntent(com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withIntent) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PostedNotification(com.onesignal.ShadowRoboNotificationManager.PostedNotification) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 FCMBroadcastReceiver_onReceived_withIntent (com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_onReceived_withIntent)1 FCMBroadcastReceiver_processBundle (com.onesignal.OneSignalPackagePrivateHelper.FCMBroadcastReceiver_processBundle)1 OneSignalPackagePrivateHelper.createInternalPayloadBundle (com.onesignal.OneSignalPackagePrivateHelper.createInternalPayloadBundle)1 PostedNotification (com.onesignal.ShadowRoboNotificationManager.PostedNotification)1 BigInteger (java.math.BigInteger)1 JSONObject (org.json.JSONObject)1 Test (org.junit.Test)1 Config (org.robolectric.annotation.Config)1