@Test public void simulateLocation_shouldNotNotifyListenerIfLessThanFastestInterval() throws Exception { TestLocationListener listener = new TestLocationListener(); shadowLocationManager.requestLocationUpdates(GPS_PROVIDER, 2000, 0, listener); long time = System.currentTimeMillis(); Location location1 = new Location(GPS_PROVIDER); location1.setTime(time); Location location2 = new Location(GPS_PROVIDER); location2.setTime(time + 1000); shadowLocationManager.simulateLocation(location1); shadowLocationManager.simulateLocation(location2); assertThat(listener.location.getTime()).isEqualTo(location1.getTime()); }
@Test public void requestLocationUpdates_shouldNotRegisterDuplicateListeners() throws Exception { TestLocationListener listener = new TestLocationListener(); shadowLocationManager.requestLocationUpdates(GPS_PROVIDER, 0, 0, listener); shadowLocationManager.requestLocationUpdates(GPS_PROVIDER, 0, 0, listener); shadowLocationManager.simulateLocation(new Location(GPS_PROVIDER)); assertThat(listener.updateCount).isEqualTo(1); }
@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); }
@Test public void simulateLocation_shouldNotNotifyListenerIfLessThanMinimumDistance() throws Exception { TestLocationListener listener = new TestLocationListener(); locationManager.requestLocationUpdates(GPS_PROVIDER, 0, 200000, listener); Location location1 = new Location(GPS_PROVIDER); location1.setLatitude(1); location1.setLongitude(2); location1.setTime(0); Location location2 = new Location(GPS_PROVIDER); location2.setLatitude(1.5); location2.setLongitude(2.5); location2.setTime(1000); shadowLocationManager.simulateLocation(location1); shadowLocationManager.simulateLocation(location2); assertThat(listener.location.getLatitude()).isEqualTo(1.0d); assertThat(listener.location.getLongitude()).isEqualTo(2.0d); }