Exemplo n.º 1
0
  @Test
  public void cancel_removesMatchingPendingIntents() {
    Intent newIntent = new Intent(Robolectric.application.getApplicationContext(), String.class);
    PendingIntent pendingIntent =
        PendingIntent.getBroadcast(
            Robolectric.application.getApplicationContext(),
            0,
            newIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.set(AlarmManager.RTC, 1337, pendingIntent);

    Intent newIntent2 = new Intent(Robolectric.application.getApplicationContext(), Integer.class);
    PendingIntent pendingIntent2 =
        PendingIntent.getBroadcast(
            Robolectric.application.getApplicationContext(),
            0,
            newIntent2,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.set(AlarmManager.RTC, 1337, pendingIntent2);

    assertEquals(2, shadowAlarmManager.getScheduledAlarms().size());

    Intent newIntent3 = new Intent(Robolectric.application.getApplicationContext(), String.class);
    PendingIntent newPendingIntent =
        PendingIntent.getBroadcast(
            Robolectric.application.getApplicationContext(),
            0,
            newIntent3,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.cancel(newPendingIntent);
    assertEquals(1, shadowAlarmManager.getScheduledAlarms().size());
  }
Exemplo n.º 2
0
  @Test
  public void shouldSupportSet() throws Exception {
    assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull();
    alarmManager.set(
        AlarmManager.ELAPSED_REALTIME,
        0,
        PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0));

    ShadowAlarmManager.ScheduledAlarm scheduledAlarm = shadowAlarmManager.getNextScheduledAlarm();
    assertThat(scheduledAlarm).isNotNull();
  }
Exemplo n.º 3
0
  @Test
  public void shouldSupportGetNextScheduledAlarm() throws Exception {
    assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull();

    long now = new Date().getTime();
    PendingIntent pendingIntent =
        PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0);
    alarmManager.set(AlarmManager.ELAPSED_REALTIME, now, pendingIntent);

    ShadowAlarmManager.ScheduledAlarm scheduledAlarm = shadowAlarmManager.getNextScheduledAlarm();
    assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull();
    assertScheduledAlarm(now, pendingIntent, scheduledAlarm);
  }
Exemplo n.º 4
0
 @Test
 public void cancel_removesMatchingPendingIntentsWithActions() {
   Intent newIntent = new Intent("someAction");
   PendingIntent pendingIntent =
       PendingIntent.getBroadcast(
           Robolectric.application.getApplicationContext(), 0, newIntent, 0);
   alarmManager.set(AlarmManager.RTC, 1337, pendingIntent);
   assertEquals(1, shadowAlarmManager.getScheduledAlarms().size());
   alarmManager.cancel(
       PendingIntent.getBroadcast(Robolectric.application, 0, new Intent("anotherAction"), 0));
   assertEquals(1, shadowAlarmManager.getScheduledAlarms().size());
   alarmManager.cancel(
       PendingIntent.getBroadcast(Robolectric.application, 0, new Intent("someAction"), 0));
   assertEquals(0, shadowAlarmManager.getScheduledAlarms().size());
 }
Exemplo n.º 5
0
 @Test
 public void setShouldReplaceDuplicates() {
   alarmManager.set(
       AlarmManager.ELAPSED_REALTIME,
       0,
       PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0));
   alarmManager.set(
       AlarmManager.ELAPSED_REALTIME,
       0,
       PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0));
   assertEquals(1, shadowAlarmManager.getScheduledAlarms().size());
 }