use of android.location.Criteria in project robolectric by robolectric.
the class ShadowLocationManagerTest method shouldReturnBestCustomProviderUsingCriteria.
@Test
public void shouldReturnBestCustomProviderUsingCriteria() throws Exception {
Criteria criteria = new Criteria();
Criteria customProviderCriteria = new Criteria();
// Manually set best provider should be returned
ArrayList<Criteria> criteriaList = new ArrayList<>();
customProviderCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteriaList.add(customProviderCriteria);
shadowLocationManager.setProviderEnabled("BEST_ENABLED_PROVIDER_WITH_CRITERIA", true, criteriaList);
assertTrue(shadowLocationManager.setBestProvider("BEST_ENABLED_PROVIDER_WITH_CRITERIA", true));
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
assertThat("BEST_ENABLED_PROVIDER_WITH_CRITERIA").isEqualTo(locationManager.getBestProvider(criteria, true));
assertTrue(shadowLocationManager.setBestProvider("BEST_ENABLED_PROVIDER_WITH_CRITERIA", true));
assertThat("BEST_ENABLED_PROVIDER_WITH_CRITERIA").isEqualTo(locationManager.getBestProvider(criteria, false));
assertThat("BEST_ENABLED_PROVIDER_WITH_CRITERIA").isEqualTo(locationManager.getBestProvider(criteria, true));
}
use of android.location.Criteria in project robolectric by robolectric.
the class ShadowLocationManagerTest method shouldReturnBestProviderUsingCriteria.
@Test
public void shouldReturnBestProviderUsingCriteria() {
Criteria criteria = new Criteria();
shadowLocationManager.setProviderEnabled(LocationManager.GPS_PROVIDER, false);
criteria.setAccuracy(Criteria.ACCURACY_FINE);
assertThat(LocationManager.GPS_PROVIDER).isEqualTo(locationManager.getBestProvider(criteria, false));
shadowLocationManager.setProviderEnabled(LocationManager.NETWORK_PROVIDER, false);
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
assertThat(LocationManager.NETWORK_PROVIDER).isEqualTo(locationManager.getBestProvider(criteria, false));
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAccuracy(Criteria.ACCURACY_FINE);
assertThat(LocationManager.NETWORK_PROVIDER).isEqualTo(locationManager.getBestProvider(criteria, false));
}
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);
}
Aggregations