Code example for LocationManager

Methods: getBestProvider

0
    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));
  } 
 
  @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);