Java 类org.robolectric.shadows.ShadowPendingIntent 实例源码

项目:grocery-reminder    文件:GroceryStoreManagerTest.java   
@Test
public void givenPlacesWhenProximityAlertIsAddedThenTheStorePendingIntentRequestCodeIsUnique() {
    Place place = createDefaultGooglePlace();
    Place place2 = new Place();
    place2.setLatitude(place.getLatitude()+1);
    place2.setLongitude(place.getLongitude());
    place2.setName("test 2");
    place2.setPlaceId("test_id2");
    List<Place> places = new ArrayList<Place>();
    places.add(place);
    places.add(place2);

    groceryStoreManager.addProximityAlerts(places);

    List<com.groceryreminder.shadows.ShadowLocationManager.ProximityAlert> proximityAlerts = shadowLocationManager.getProximityAlerts();
    assertEquals(places.size(), proximityAlerts.size());

    ShadowPendingIntent shadowPendingIntent1 = Shadows.shadowOf(proximityAlerts.get(0).getPendingIntent());
    ShadowPendingIntent shadowPendingIntent2 = Shadows.shadowOf(proximityAlerts.get(1).getPendingIntent());
    assertNotEquals(shadowPendingIntent1.getRequestCode(), shadowPendingIntent2.getRequestCode());
}
项目:AndroidTextManager    文件:NotificationsTest.java   
private void verifyReturnsMainActivity() {
    // Tapping on the summary should go to MainActivity
    for (Notification notification : mNotificationManager.getAllNotifications()) {
        if ((notification.flags & Notification.FLAG_GROUP_SUMMARY) != Notification.FLAG_GROUP_SUMMARY) {
            continue;
        }

        ShadowPendingIntent pendingIntent = Shadows.shadowOf(notification.contentIntent);

        // We're launching an activity
        assertTrue(pendingIntent.isActivityIntent());

        // There should be 1 intent. The root (MainActivity)
        assertEquals(1, pendingIntent.getSavedIntents().length);
        Intent mainActivity = pendingIntent.getSavedIntent();
        assertEquals(MainActivity.class.getCanonicalName(), mainActivity.getComponent().getClassName());
    }
}
项目:crockpod    文件:AlarmServiceRepositoryTest.java   
@Test
public void setAddsTheAlarmIntent() {
    repo.set(alarm);

    ShadowAlarmManager.ScheduledAlarm nextAlarm = shadowAlarmManager.getNextScheduledAlarm();
    ShadowPendingIntent shadowPendingIntent = shadowOf(nextAlarm.operation);

    Intent expectedIntent = new Intent(context, AlarmReceiver.class);
    expectedIntent.putExtra(Alarm.ALARM_ID_KEY, alarm.getId());

    assertEquals(triggerTime.getMillis(), nextAlarm.triggerAtTime);
    assertTrue(expectedIntent.filterEquals(shadowPendingIntent.getSavedIntent()));
    assertEquals(PendingIntent.FLAG_UPDATE_CURRENT, shadowPendingIntent.getFlags());
}
项目:grocery-reminder    文件:GroceryStoreManagerTest.java   
@Test
public void whenProximityAlertIsAddedThenThePendingIntentIsSetToBroadcast() {
    Place place = createDefaultGooglePlace();
    List<Place> places = new ArrayList<Place>();
    places.add(place);

    groceryStoreManager.addProximityAlerts(places);

    com.groceryreminder.shadows.ShadowLocationManager.ProximityAlert proximityAlert = shadowLocationManager.getProximityAlert(place.getLatitude(), place.getLongitude());
    ShadowPendingIntent shadowPendingIntent = Shadows.shadowOf(proximityAlert.getPendingIntent());

    assertTrue(shadowPendingIntent.isBroadcastIntent());
}
项目:grocery-reminder    文件:GroceryStoreManagerTest.java   
@Test
public void whenProximityAlertIsAddedThenTheStorePendingIntentIsSet() {
    Place place = createDefaultGooglePlace();
    List<Place> places = new ArrayList<Place>();
    places.add(place);

    groceryStoreManager.addProximityAlerts(places);

    com.groceryreminder.shadows.ShadowLocationManager.ProximityAlert proximityAlert = shadowLocationManager.getProximityAlert(place.getLatitude(), place.getLongitude());
    ShadowPendingIntent shadowPendingIntent = Shadows.shadowOf(proximityAlert.getPendingIntent());
    ShadowIntent shadowIntent = Shadows.shadowOf(shadowPendingIntent.getSavedIntent());

    assertEquals(GroceryReminderConstants.ACTION_STORE_PROXIMITY_EVENT, shadowIntent.getAction());
}
项目:grocery-reminder    文件:GroceryStoreManagerTest.java   
@Test
public void whenProximityAlertIsAddedThenTheStorePendingIntentCancelsTheCurrentRequest() {
    Place place = createDefaultGooglePlace();
    List<Place> places = new ArrayList<Place>();
    places.add(place);

    groceryStoreManager.addProximityAlerts(places);

    com.groceryreminder.shadows.ShadowLocationManager.ProximityAlert proximityAlert = shadowLocationManager.getProximityAlert(place.getLatitude(), place.getLongitude());
    ShadowPendingIntent shadowPendingIntent = Shadows.shadowOf(proximityAlert.getPendingIntent());

    assertEquals(PendingIntent.FLAG_CANCEL_CURRENT, shadowPendingIntent.getFlags());
}
项目:grocery-reminder    文件:GroceryStoreManagerTest.java   
@Test
public void whenProximityAlertIsAddedThenTheStorePendingIntentContainsTheStoreName() {
    Place place = createDefaultGooglePlace();
    List<Place> places = new ArrayList<Place>();
    places.add(place);

    groceryStoreManager.addProximityAlerts(places);

    com.groceryreminder.shadows.ShadowLocationManager.ProximityAlert proximityAlert = shadowLocationManager.getProximityAlert(place.getLatitude(), place.getLongitude());
    ShadowPendingIntent shadowPendingIntent = Shadows.shadowOf(proximityAlert.getPendingIntent());

    assertEquals(place.getName(), shadowPendingIntent.getSavedIntent().getStringExtra(ReminderContract.Locations.NAME));
}
项目:grocery-reminder    文件:GroceryStoreNotificationManagerTest.java   
@Test
public void givenANotificationIsSentWhenTheNotificationIsActedOnThenTheRemindersActivityIsLaunched() {
    groceryStoreNotificationManager.sendNotification(buildIntentToListenFor());

    ShadowNotificationManager shadowNotificationManager = getShadowNotificationManager();
    ShadowNotification notification = Shadows.shadowOf(shadowNotificationManager.getNotification(GroceryReminderConstants.NOTIFICATION_PROXIMITY_ALERT));
    ShadowPendingIntent shadowPendingIntent = Shadows.shadowOf(notification.getRealNotification().contentIntent);
    ShadowIntent shadowIntent = Shadows.shadowOf(shadowPendingIntent.getSavedIntent());

    assertEquals(RemindersActivity.class.getName(), shadowIntent.getComponent().getClassName());
}
项目:AndroidTextManager    文件:NotificationsTest.java   
private void verifyReturnsMessageActivity(long expectedThreadId) {
    for (Notification notification : mNotificationManager.getAllNotifications()) {
        ShadowPendingIntent pendingIntent = Shadows.shadowOf(notification.contentIntent);

        // We're launching an activity
        assertTrue(pendingIntent.isActivityIntent());

        // There should be 2 intents. The root (MainActivity) and the child (MessageActivity).
        assertEquals(2, pendingIntent.getSavedIntents().length);
        Intent mainActivity = pendingIntent.getSavedIntents()[0];
        Intent messageActivity = pendingIntent.getSavedIntents()[1];
        assertEquals(MainActivity.class.getCanonicalName(), mainActivity.getComponent().getClassName());
        assertEquals(MessageActivity.class.getCanonicalName(), messageActivity.getComponent().getClassName());

        // MessageActivity should have extras for the thread we care about
        // We don't care about the implementation (thread vs id).
        String threadId = messageActivity.getStringExtra(MessageActivity.EXTRA_THREAD_ID);
        Thread thread = messageActivity.getParcelableExtra(MessageActivity.EXTRA_THREAD);
        if (threadId != null) {
            assertEquals(Long.toString(expectedThreadId), threadId);
        } else if (thread != null) {
            assertEquals(Long.toString(expectedThreadId), thread.getId());
        } else {
            throw new IllegalStateException("No thread or thread id given");
        }
    }
}
项目:SmsRadar    文件:SmsRadarServiceTest.java   
@Test
public void shouldRestartServiceUsingAlarmManagerWhenTaskRemoved() {
    when(mockedTimeProvider.getDate()).thenReturn(new Date(ANY_TIME));

    startSmsInterceptorService();
    smsRadarService.onTaskRemoved(ANY_INTENT);

    ArgumentCaptor<PendingIntent> pendingIntentArgumentCaptor = ArgumentCaptor.forClass(PendingIntent.class);
    verify(mockedAlarmManager).set(eq(AlarmManager.RTC_WAKEUP), eq(ANY_TIME + ONE_SECOND),
            pendingIntentArgumentCaptor.capture());
    PendingIntent capturedPendingIntent = pendingIntentArgumentCaptor.getValue();
    ShadowPendingIntent pendingIntent = Robolectric.shadowOf(capturedPendingIntent);
    ShadowIntent intent = Robolectric.shadowOf(pendingIntent.getSavedIntent());
    assertEquals(SmsRadarService.class, intent.getIntentClass());
}
项目:FullRobolectricTestSample    文件:Robolectric.java   
public static ShadowPendingIntent shadowOf(PendingIntent instance) {
  return (ShadowPendingIntent) shadowOf_(instance);
}