providerEntry.criteria = criteria; providersEnabled.put(provider, providerEntry); List<LocationListener> locationUpdateListeners = new ArrayList<>(getRequestLocationUpdateListeners()); for (LocationListener locationUpdateListener : locationUpdateListeners) { if (isEnabled) {
@Test public void shouldStoreRequestLocationUpdateListeners() throws Exception { TestLocationListener listener = new TestLocationListener(); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, 2.0f, listener); assertSame(shadowLocationManager.getRequestLocationUpdateListeners().get(0), listener); }
@Test public void shouldRemoveLocationListeners() throws Exception { TestLocationListener listener = new TestLocationListener(); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, 2.0f, listener); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 2.0f, listener); TestLocationListener otherListener = new TestLocationListener(); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, 2.0f, otherListener); locationManager.removeUpdates(listener); List<LocationListener> expected = new ArrayList<>(); expected.add(otherListener); assertThat(shadowLocationManager.getRequestLocationUpdateListeners()).isEqualTo(expected); }
@Test public void shouldNotThrowExceptionIfLocationListenerRemovedInsideOnLocationChanged() throws Exception { TestLocationListenerSelfRemoval listener = new TestLocationListenerSelfRemoval(locationManager); shadowLocationManager.requestLocationUpdates(GPS_PROVIDER, 0, 0, listener); Location location = new Location(GPS_PROVIDER); location.setLatitude(0); location.setLongitude(0); shadowLocationManager.simulateLocation(location); assertThat(shadowLocationManager.getRequestLocationUpdateListeners().size()).isEqualTo(0); }
providerEntry.criteria = criteria; providersEnabled.put(provider, providerEntry); List<LocationListener> locationUpdateListeners = new ArrayList<>(getRequestLocationUpdateListeners()); for (LocationListener locationUpdateListener : locationUpdateListeners) { if (isEnabled) {
providerEntry.criteria = criteria; providersEnabled.put(provider, providerEntry); List<LocationListener> locationUpdateListeners = new ArrayList<>(getRequestLocationUpdateListeners()); for (LocationListener locationUpdateListener : locationUpdateListeners) { if (isEnabled) {
providerEntry.criteria = criteria; providersEnabled.put(provider, providerEntry); List<LocationListener> locationUpdateListeners = new ArrayList<>(getRequestLocationUpdateListeners()); for (LocationListener locationUpdateListener : locationUpdateListeners) { if (isEnabled) {
providerEntry.criteria = criteria; providersEnabled.put(provider, providerEntry); List<LocationListener> locationUpdateListeners = new ArrayList<>(getRequestLocationUpdateListeners()); for (LocationListener locationUpdateListener : locationUpdateListeners) { if (isEnabled) {