Code example for LocationManager: Getting continuous location updates

Methods: removeUpdatesrequestLocationUpdates

0
  @Test 
  public void shouldKeepTrackOfWhichProvidersAListenerIsBoundTo_withoutDuplicates_inAnyOrder() throws Exception { 
    TestLocationListener listener1 = new TestLocationListener();
    TestLocationListener listener2 = new TestLocationListener();
 
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, 1, listener1);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, listener1);
 
    Set<String> listOfExpectedProvidersForListener1 = new HashSet<String>();
    listOfExpectedProvidersForListener1.add(LocationManager.NETWORK_PROVIDER);
    listOfExpectedProvidersForListener1.add(LocationManager.GPS_PROVIDER);
 
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, 1, listener2);
    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, 1, listener2);
 
    Set<String> listOfExpectedProvidersForListener2 = new HashSet<String>();
    listOfExpectedProvidersForListener2.add(LocationManager.NETWORK_PROVIDER);
 
    assertEquals(listOfExpectedProvidersForListener1, new HashSet<String>(shadowLocationManager.getProvidersForListener(listener1)));
    assertEquals(listOfExpectedProvidersForListener2, new HashSet<String>(shadowLocationManager.getProvidersForListener(listener2)));
 
    locationManager.removeUpdates(listener1);
    assertEquals(0, shadowLocationManager.getProvidersForListener(listener1).size());
  } 
 
  @Test 
  public void shouldRemoveLocationListeners() throws Exception {