AndroidLocationClient extends BaseLocationClient implements android.location.LocationListener { @Override public void start() { if (getProvider() == null) { if (getListener() != null) { getListener().onClientStartFailure(); } return; } isConnected = true; if (getListener() != null) { getListener().onClientStart(); } } AndroidLocationClient(@NonNull Context context);   AndroidLocationClient(@NonNull LocationManager locationManager); @Override void start(); @Override void stop(); @Override @SuppressLint("MissingPermission") // Permission checks for location services handled in widgets void requestLocationUpdates(@NonNull LocationListener locationListener); @Override void stopLocationUpdates(); @Override @SuppressLint("MissingPermission") // Permission checks for location services handled in widgets Location getLastLocation(); @Override boolean isMonitoringLocation(); @Override boolean canSetUpdateIntervals(); @Override void setUpdateIntervals(long updateInterval, long fastestUpdateInterval); @Override void resetUpdateIntervals(); @Override void onLocationChanged(Location location); @Override void onStatusChanged(String provider, int status, Bundle extras); @Override void onProviderEnabled(String provider); @Override void onProviderDisabled(String provider);  }
@Test public void passiveProviderOnlyShouldFailOnHighAndBalancedPriorities() { List<String> highAccuracyProviders = ImmutableList.of(PASSIVE_PROVIDER); when(locationManager.getProviders(true)).thenReturn(highAccuracyProviders); TestClientListener testListener = new TestClientListener(); androidLocationClient.setListener(testListener); androidLocationClient.setPriority(PRIORITY_HIGH_ACCURACY); androidLocationClient.start(); assertFalse(testListener.wasStartCalled()); assertTrue(testListener.wasStartFailureCalled()); assertFalse(testListener.wasStopCalled()); testListener.reset(); androidLocationClient.setPriority(PRIORITY_BALANCED_POWER_ACCURACY); androidLocationClient.start(); assertFalse(testListener.wasStartCalled()); assertTrue(testListener.wasStartFailureCalled()); assertFalse(testListener.wasStopCalled()); testListener.reset(); androidLocationClient.setPriority(PRIORITY_LOW_POWER); androidLocationClient.start(); assertTrue(testListener.wasStartCalled()); assertFalse(testListener.wasStartFailureCalled()); assertFalse(testListener.wasStopCalled()); testListener.reset(); androidLocationClient.setPriority(PRIORITY_NO_POWER); androidLocationClient.start(); assertTrue(testListener.wasStartCalled()); assertFalse(testListener.wasStartFailureCalled()); assertFalse(testListener.wasStopCalled()); testListener.reset(); }
@Test public void networkProviderOnlyShouldFailOnNoPowerPriority() { List<String> highAccuracyProviders = ImmutableList.of(NETWORK_PROVIDER); when(locationManager.getProviders(true)).thenReturn(highAccuracyProviders); TestClientListener testListener = new TestClientListener(); androidLocationClient.setListener(testListener); androidLocationClient.setPriority(PRIORITY_NO_POWER); androidLocationClient.start(); assertFalse(testListener.wasStartCalled()); assertTrue(testListener.wasStartFailureCalled()); assertFalse(testListener.wasStopCalled()); testListener.reset(); androidLocationClient.setPriority(PRIORITY_LOW_POWER); androidLocationClient.start(); assertTrue(testListener.wasStartCalled()); assertFalse(testListener.wasStartFailureCalled()); assertFalse(testListener.wasStopCalled()); testListener.reset(); androidLocationClient.setPriority(PRIORITY_BALANCED_POWER_ACCURACY); androidLocationClient.start(); assertTrue(testListener.wasStartCalled()); assertFalse(testListener.wasStartFailureCalled()); assertFalse(testListener.wasStopCalled()); testListener.reset(); androidLocationClient.setPriority(PRIORITY_HIGH_ACCURACY); androidLocationClient.start(); assertTrue(testListener.wasStartCalled()); assertFalse(testListener.wasStartFailureCalled()); assertFalse(testListener.wasStopCalled()); testListener.reset(); }
@Test public void gpsProviderOnlyShouldFailOnLowAndNoPowerPriorities() { List<String> highAccuracyProviders = ImmutableList.of(GPS_PROVIDER); when(locationManager.getProviders(true)).thenReturn(highAccuracyProviders); TestClientListener testListener = new TestClientListener(); androidLocationClient.setListener(testListener); androidLocationClient.setPriority(PRIORITY_NO_POWER); androidLocationClient.start(); assertFalse(testListener.wasStartCalled()); assertTrue(testListener.wasStartFailureCalled()); assertFalse(testListener.wasStopCalled()); testListener.reset(); androidLocationClient.setPriority(PRIORITY_LOW_POWER); androidLocationClient.start(); assertFalse(testListener.wasStartCalled()); assertTrue(testListener.wasStartFailureCalled()); assertFalse(testListener.wasStopCalled()); testListener.reset(); androidLocationClient.setPriority(PRIORITY_BALANCED_POWER_ACCURACY); androidLocationClient.start(); assertTrue(testListener.wasStartCalled()); assertFalse(testListener.wasStartFailureCalled()); assertFalse(testListener.wasStopCalled()); testListener.reset(); androidLocationClient.setPriority(PRIORITY_HIGH_ACCURACY); androidLocationClient.start(); assertTrue(testListener.wasStartCalled()); assertFalse(testListener.wasStartFailureCalled()); assertFalse(testListener.wasStopCalled()); testListener.reset(); }