Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Commit

Permalink
Add test for toggling engines
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarah Lensing committed Jun 20, 2016
1 parent 6a8057c commit 7299c63
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.Context;
import android.location.Location;
import android.os.Looper;
import android.support.annotation.VisibleForTesting;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -123,14 +124,6 @@ public void shutdown() {
shutdownAllEngines();
}

public List<LocationListener> getListeners() {
List<LocationListener> listeners = new ArrayList<>();
for (LocationEngine engine : engineListeners.keySet()) {
listeners.addAll(engineListeners.get(engine));
}
return listeners;
}

/**
* First checks for an existing {@link LocationEngine} given a request. Creates a new one if
* none exist.
Expand Down Expand Up @@ -232,4 +225,13 @@ private void shutdownAllEngines() {
}
locationEngines.clear();
}

@VisibleForTesting
public List<LocationListener> getListeners() {
List<LocationListener> listeners = new ArrayList<>();
for (LocationEngine engine : engineListeners.keySet()) {
listeners.addAll(engineListeners.get(engine));
}
return listeners;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ public void removeLocationUpdates_shouldUnregisterAllListeners() throws Exceptio
}

@Test
public void setMockMode_shouldToggleAllListenersWhenTrue() throws Exception {
public void setMockMode_shouldUnregisterAllListenersWhenTrue() throws Exception {
TestLocationListener listener = new TestLocationListener();
LocationRequest request = LocationRequest.create();
api.requestLocationUpdates(request, listener);
api.setMockMode(true);
assertThat(api.getListeners()).hasSize(1);
assertThat(shadowLocationManager.getRequestLocationUpdateListeners()).isEmpty();
}

@Test
Expand All @@ -219,6 +219,16 @@ public void setMockMode_shouldNotRegisterDuplicateListeners() throws Exception {
api.requestLocationUpdates(request, listener);
api.setMockMode(false);
api.requestLocationUpdates(request, listener);
assertThat(shadowLocationManager.getRequestLocationUpdateListeners()).hasSize(4);
}

@Test
public void setMockMode_shouldToggleEngines() {
TestLocationListener listener = new TestLocationListener();
LocationRequest request = LocationRequest.create();
api.requestLocationUpdates(request, listener);
api.setMockMode(true);
api.requestLocationUpdates(request, listener);
assertThat(api.getListeners()).hasSize(2);
}

Expand Down

0 comments on commit 7299c63

Please sign in to comment.