Search in sources :

Example 1 with ProviderProperties

use of org.robolectric.shadows.ShadowLocationManager.ProviderProperties in project robolectric by robolectric.

the class ShadowLocationManagerTest method testGetProvider.

@Test
@Config(minSdk = VERSION_CODES.KITKAT)
public void testGetProvider() {
    LocationProvider p;
    p = locationManager.getProvider(GPS_PROVIDER);
    assertThat(p).isNotNull();
    assertThat(p.getName()).isEqualTo(GPS_PROVIDER);
    p = locationManager.getProvider(NETWORK_PROVIDER);
    assertThat(p).isNotNull();
    assertThat(p.getName()).isEqualTo(NETWORK_PROVIDER);
    p = locationManager.getProvider(PASSIVE_PROVIDER);
    assertThat(p).isNotNull();
    assertThat(p.getName()).isEqualTo(PASSIVE_PROVIDER);
    shadowLocationManager.setProviderProperties(MY_PROVIDER, new ProviderProperties(true, false, true, false, true, false, true, Criteria.POWER_HIGH, Criteria.ACCURACY_COARSE));
    p = locationManager.getProvider(MY_PROVIDER);
    assertThat(p).isNotNull();
    assertThat(p.getName()).isEqualTo(MY_PROVIDER);
    assertThat(p.requiresNetwork()).isTrue();
    assertThat(p.requiresSatellite()).isFalse();
    assertThat(p.requiresCell()).isTrue();
    assertThat(p.hasMonetaryCost()).isFalse();
    assertThat(p.supportsAltitude()).isTrue();
    assertThat(p.supportsSpeed()).isFalse();
    assertThat(p.supportsBearing()).isTrue();
    assertThat(p.getPowerRequirement()).isEqualTo(Criteria.POWER_HIGH);
    assertThat(p.getAccuracy()).isEqualTo(Criteria.ACCURACY_COARSE);
    p = locationManager.getProvider("noProvider");
    assertThat(p).isNull();
}
Also used : LocationProvider(android.location.LocationProvider) ProviderProperties(org.robolectric.shadows.ShadowLocationManager.ProviderProperties) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 2 with ProviderProperties

use of org.robolectric.shadows.ShadowLocationManager.ProviderProperties in project robolectric by robolectric.

the class ShadowLocationManagerTest method testGetProviderProperties.

@Test
@Config(minSdk = VERSION_CODES.S)
public void testGetProviderProperties() {
    android.location.provider.ProviderProperties p;
    shadowLocationManager.setProviderProperties(MY_PROVIDER, new ProviderProperties(true, false, true, false, true, false, true, Criteria.POWER_HIGH, Criteria.ACCURACY_COARSE));
    p = locationManager.getProviderProperties(MY_PROVIDER);
    assertThat(p).isNotNull();
    assertThat(p.hasNetworkRequirement()).isTrue();
    assertThat(p.hasSatelliteRequirement()).isFalse();
    assertThat(p.hasCellRequirement()).isTrue();
    assertThat(p.hasMonetaryCost()).isFalse();
    assertThat(p.hasAltitudeSupport()).isTrue();
    assertThat(p.hasSpeedSupport()).isFalse();
    assertThat(p.hasBearingSupport()).isTrue();
    assertThat(p.getPowerUsage()).isEqualTo(Criteria.POWER_HIGH);
    assertThat(p.getAccuracy()).isEqualTo(Criteria.ACCURACY_COARSE);
    shadowLocationManager.setProviderProperties(MY_PROVIDER, new ProviderProperties(false, true, false, true, false, true, false, android.location.provider.ProviderProperties.POWER_USAGE_LOW, android.location.provider.ProviderProperties.ACCURACY_FINE));
    p = locationManager.getProviderProperties(MY_PROVIDER);
    assertThat(p).isNotNull();
    assertThat(p.hasNetworkRequirement()).isFalse();
    assertThat(p.hasSatelliteRequirement()).isTrue();
    assertThat(p.hasCellRequirement()).isFalse();
    assertThat(p.hasMonetaryCost()).isTrue();
    assertThat(p.hasAltitudeSupport()).isFalse();
    assertThat(p.hasSpeedSupport()).isTrue();
    assertThat(p.hasBearingSupport()).isFalse();
    assertThat(p.getPowerUsage()).isEqualTo(android.location.provider.ProviderProperties.POWER_USAGE_LOW);
    assertThat(p.getAccuracy()).isEqualTo(android.location.provider.ProviderProperties.ACCURACY_FINE);
    p = locationManager.getProviderProperties("noProvider");
    assertThat(p).isNull();
}
Also used : ProviderProperties(org.robolectric.shadows.ShadowLocationManager.ProviderProperties) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

Test (org.junit.Test)2 Config (org.robolectric.annotation.Config)2 ProviderProperties (org.robolectric.shadows.ShadowLocationManager.ProviderProperties)2 LocationProvider (android.location.LocationProvider)1