@Test
public void shouldRemovePendingIntentsWhenRequestingLocationUpdatesUsingLocationListeners() throws Exception {
Intent someIntent = new Intent("some_action");
PendingIntent someLocationListenerPendingIntent =
PendingIntent.getBroadcast(context, 0, someIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent someOtherIntent = new Intent("some_other_action");
PendingIntent someOtherLocationListenerPendingIntent =
PendingIntent.getBroadcast(context, 0, someOtherIntent, PendingIntent.FLAG_UPDATE_CURRENT);
shadowLocationManager.setProviderEnabled(GPS_PROVIDER, true);
shadowLocationManager.setBestProvider(LocationManager.GPS_PROVIDER, true);
shadowLocationManager.setProviderEnabled(NETWORK_PROVIDER, true);
locationManager.requestLocationUpdates(GPS_PROVIDER, 0, 0, someLocationListenerPendingIntent);
locationManager.requestLocationUpdates(NETWORK_PROVIDER, 0, 0, someOtherLocationListenerPendingIntent);
locationManager.removeUpdates(someLocationListenerPendingIntent);
Map<PendingIntent, String> expectedProviders = new HashMap<>();
expectedProviders.put(someOtherLocationListenerPendingIntent, NETWORK_PROVIDER);
assertThat(shadowLocationManager.getRequestLocationUdpateProviderPendingIntents()).isEqualTo(expectedProviders);
}