Пример #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());
  }
Пример #2
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());
 }
Пример #3
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());
 }