use of android.location.Criteria in project robolectric by robolectric.
the class ShadowLocationManagerTest method shouldRemovePendingIntentsWhenRequestingLocationUpdatesUsingCriteria.
@Test
public void shouldRemovePendingIntentsWhenRequestingLocationUpdatesUsingCriteria() throws Exception {
Intent someIntent = new Intent("some_action");
PendingIntent someLocationListenerPendingIntent = PendingIntent.getBroadcast(ShadowApplication.getInstance().getApplicationContext(), 0, someIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent someOtherIntent = new Intent("some_other_action");
PendingIntent someOtherLocationListenerPendingIntent = PendingIntent.getBroadcast(ShadowApplication.getInstance().getApplicationContext(), 0, someOtherIntent, PendingIntent.FLAG_UPDATE_CURRENT);
shadowLocationManager.setProviderEnabled(GPS_PROVIDER, true);
shadowLocationManager.setBestProvider(LocationManager.GPS_PROVIDER, true);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
locationManager.requestLocationUpdates(0, 0, criteria, someLocationListenerPendingIntent);
locationManager.requestLocationUpdates(0, 0, criteria, someOtherLocationListenerPendingIntent);
locationManager.removeUpdates(someLocationListenerPendingIntent);
Map<PendingIntent, Criteria> expectedCriteria = new HashMap<>();
expectedCriteria.put(someOtherLocationListenerPendingIntent, criteria);
assertThat(shadowLocationManager.getRequestLocationUdpateCriteriaPendingIntents()).isEqualTo(expectedCriteria);
}
use of android.location.Criteria in project robolectric by robolectric.
the class ShadowLocationManagerTest method shouldStoreBestProviderCriteriaAndEnabledOnlyFlag.
@Test
public void shouldStoreBestProviderCriteriaAndEnabledOnlyFlag() throws Exception {
Criteria criteria = new Criteria();
assertNull(locationManager.getBestProvider(criteria, true));
assertSame(criteria, shadowLocationManager.getLastBestProviderCriteria());
assertTrue(shadowLocationManager.getLastBestProviderEnabledOnly());
}
use of android.location.Criteria in project robolectric by robolectric.
the class ShadowLocationManagerTest method shouldRegisterLocationUpdatesWhenCriteriaGiven.
@Test
public void shouldRegisterLocationUpdatesWhenCriteriaGiven() throws Exception {
shadowLocationManager.setProviderEnabled(NETWORK_PROVIDER, true);
shadowLocationManager.setBestProvider(LocationManager.NETWORK_PROVIDER, true);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
Intent someIntent = new Intent("some_action");
PendingIntent someLocationListenerPendingIntent = PendingIntent.getBroadcast(ShadowApplication.getInstance().getApplicationContext(), 0, someIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Criteria someCriteria = new Criteria();
someCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
locationManager.requestLocationUpdates(0, 0, someCriteria, someLocationListenerPendingIntent);
assertThat(shadowLocationManager.getRequestLocationUdpateCriteriaPendingIntents().get(someLocationListenerPendingIntent)).isEqualTo(someCriteria);
}
use of android.location.Criteria in project robolectric by robolectric.
the class ShadowLocationManagerTest method shouldThrowExceptionIfTheBestProviderIsUnknown.
@Test
public void shouldThrowExceptionIfTheBestProviderIsUnknown() throws Exception {
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
try {
shadowLocationManager.setBestProvider("BEST_ENABLED_PROVIDER", true);
Assert.fail("The best provider is unknown!");
} catch (Exception e) {
// No worries, everything is fine...
}
}
use of android.location.Criteria in project ignition by mttkay.
the class AbstractIgnitedLocationManagerTest method shouldNotRequestUpdatesFromGpsIfBatteryLow.
@Test
public void shouldNotRequestUpdatesFromGpsIfBatteryLow() {
sendBatteryLevelChangedBroadcast(10);
resume();
Map<PendingIntent, Criteria> locationPendingIntents = shadowLocationManager.getRequestLocationUdpateCriteriaPendingIntents();
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
assertThat("Updates from " + LocationManager.GPS_PROVIDER + " provider shouldn't be requested when battery power is low!", !locationPendingIntents.containsValue(criteria));
}
Aggregations