AndroidGpsLocationClient extends BaseLocationClient { @Override public void stopLocationUpdates() { if (isMonitoringLocation()) { lastLocation = null; locationManager.removeUpdates(androidGpsLocationListener); for (LocationListener locationListener : getLocationListeners()) { locationManager.removeUpdates(locationListener); } clearLocationListeners(); } unregisterForGpsStoppedEvent(); } AndroidGpsLocationClient(@NonNull Context context); @Override void stopLocationUpdates(); @SuppressLint("MissingPermission") @Nullable @Override Location getLastLocation(); @Override void requestLocationUpdates(@NonNull LocationListener locationListener); @Override void setUpdateIntervals(long updateInterval, long fastestUpdateInterval); @NonNull @Override String getProvider(); @Override void close();  }
@Test public void stopLocationUpdatesShouldSetListenerToNullWhenListenerIsCurrentlySet() { LocationListener locationListener = Mockito.mock(LocationListener.class); androidGpsLocationClient.addLocationListener(locationListener); Assert.assertTrue(androidGpsLocationClient.getLocationListeners().size() > 0); androidGpsLocationClient.stopLocationUpdates(); Assert.assertEquals(0, androidGpsLocationClient.getLocationListeners().size()); androidGpsLocationClient.setLocationListener(locationListener); Assert.assertNotNull(androidGpsLocationClient.getLocationListener()); androidGpsLocationClient.stopLocationUpdates(); Assert.assertNull(androidGpsLocationClient.getLocationListener()); }
@Test public void stopLocationUpdatesShouldCallLocationManagerRemoveUpdates() { LocationListener locationListener = Mockito.mock(LocationListener.class); LocationManager locationManager = Mockito.spy((LocationManager) ReflectionHelpers.getField(androidGpsLocationClient, "locationManager")); ReflectionHelpers.setField(androidGpsLocationClient, "locationManager", locationManager); androidGpsLocationClient.addLocationListener(locationListener); Assert.assertEquals(1, androidGpsLocationClient.getLocationListeners().size()); androidGpsLocationClient.stopLocationUpdates(); Mockito.verify(locationManager, Mockito.times(2)).removeUpdates(Mockito.any(LocationListener.class)); }