Search in sources :

Example 1 with ShadowPendingIntent

use of org.robolectric.shadows.ShadowPendingIntent in project sms-backup-plus by jberkel.

the class AlarmManagerDriverTest method assertAlarmScheduled.

private Intent assertAlarmScheduled(String ofExpectedType) {
    AlarmManager alarmManager = (AlarmManager) RuntimeEnvironment.application.getSystemService(Context.ALARM_SERVICE);
    ShadowAlarmManager shadow = shadowOf(alarmManager);
    ShadowAlarmManager.ScheduledAlarm nextScheduledAlarm = shadow.getNextScheduledAlarm();
    assertThat(nextScheduledAlarm.type).isEqualTo(AlarmManager.RTC_WAKEUP);
    assertThat(nextScheduledAlarm.triggerAtTime).isGreaterThan(0L);
    PendingIntent pendingIntent = nextScheduledAlarm.operation;
    ShadowPendingIntent shadowPendingIntent = shadowOf(pendingIntent);
    ComponentName component = shadowPendingIntent.getSavedIntent().getComponent();
    assertThat(component.getPackageName()).isEqualTo("com.zegoggles.smssync");
    assertThat(component.getClassName()).isEqualTo("com.zegoggles.smssync.service.SmsBackupService");
    assertThat(shadowPendingIntent.getFlags()).isEqualTo(FLAG_UPDATE_CURRENT);
    assertThat(shadowPendingIntent.getSavedIntent().getAction()).isNotEmpty();
    assertThat(shadowPendingIntent.getSavedIntent().getAction()).isEqualTo(ofExpectedType);
    return shadowPendingIntent.getSavedIntent();
}
Also used : AlarmManager(android.app.AlarmManager) ShadowAlarmManager(org.robolectric.shadows.ShadowAlarmManager) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) ShadowPendingIntent(org.robolectric.shadows.ShadowPendingIntent) ShadowAlarmManager(org.robolectric.shadows.ShadowAlarmManager) ShadowPendingIntent(org.robolectric.shadows.ShadowPendingIntent)

Example 2 with ShadowPendingIntent

use of org.robolectric.shadows.ShadowPendingIntent in project iterable-android-sdk by Iterable.

the class IterableNotificationTest method testNoAction.

@Test
public void testNoAction() throws Exception {
    Bundle notif = new Bundle();
    notif.putString(IterableConstants.ITERABLE_DATA_KEY, getResourceString("push_payload_no_action.json"));
    IterableNotificationBuilder iterableNotification = postNotification(notif);
    StatusBarNotification statusBarNotification = mNotificationManager.getActiveNotifications()[0];
    Notification notification = statusBarNotification.getNotification();
    assertEquals(1, notification.actions.length);
    assertEquals("No action", notification.actions[0].title);
    ShadowPendingIntent shadowPendingIntent = shadowOf(notification.actions[0].actionIntent);
    Intent savedIntent = shadowPendingIntent.getSavedIntent();
    assertEquals(IterableConstants.ACTION_PUSH_ACTION, savedIntent.getAction());
    assertEquals("button1", savedIntent.getStringExtra(IterableConstants.ACTION_IDENTIFIER));
}
Also used : StatusBarNotification(android.service.notification.StatusBarNotification) Bundle(android.os.Bundle) ShadowPendingIntent(org.robolectric.shadows.ShadowPendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) StatusBarNotification(android.service.notification.StatusBarNotification) ShadowPendingIntent(org.robolectric.shadows.ShadowPendingIntent) Test(org.junit.Test)

Aggregations

PendingIntent (android.app.PendingIntent)2 ShadowPendingIntent (org.robolectric.shadows.ShadowPendingIntent)2 AlarmManager (android.app.AlarmManager)1 Notification (android.app.Notification)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 StatusBarNotification (android.service.notification.StatusBarNotification)1 Test (org.junit.Test)1 ShadowAlarmManager (org.robolectric.shadows.ShadowAlarmManager)1