Refactoring the LocationProvider test of latestLocation
This commit is contained in:
parent
6a2eddeea6
commit
8aa0c856ab
2 changed files with 3 additions and 15 deletions
|
@ -62,4 +62,4 @@ public class MyService extends Service implements LocationListener {
|
||||||
public void onProviderDisabled(String s) {}
|
public void onProviderDisabled(String s) {}
|
||||||
@Override
|
@Override
|
||||||
public void onProviderEnabled(String s) {}
|
public void onProviderEnabled(String s) {}
|
||||||
}
|
}
|
|
@ -41,13 +41,12 @@ public class MyServiceTest extends ServiceTestCase {
|
||||||
MyService mainService = setupMyService(locationManager);
|
MyService mainService = setupMyService(locationManager);
|
||||||
simulateNewLocation(locationManager);
|
simulateNewLocation(locationManager);
|
||||||
|
|
||||||
assertTrue(areTheLocationsEqual(someLocation, mainService.latestLocation()));
|
assertTrue(someLocation.equals(mainService.latestLocation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void simulateNewLocation(LocationManager locationManager) {
|
private void simulateNewLocation(LocationManager locationManager) {
|
||||||
ShadowLocationManager shadowLocationManager = Shadows.shadowOf(locationManager);
|
ShadowLocationManager shadowLocationManager = Shadows.shadowOf(locationManager);
|
||||||
shadowLocationManager.simulateLocation(location(CAN_PROVIDER,
|
shadowLocationManager.simulateLocation(someLocation);
|
||||||
someLocation.getLatitude(), someLocation.getLongitude()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private MyService setupMyService(LocationManager locationManager) {
|
private MyService setupMyService(LocationManager locationManager) {
|
||||||
|
@ -56,17 +55,6 @@ public class MyServiceTest extends ServiceTestCase {
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean areTheLocationsEqual(Location first, Location second) {
|
|
||||||
// timestamp is different
|
|
||||||
if ( (first.getAccuracy() == second.getAccuracy()) &&
|
|
||||||
(first.getLatitude() == second.getLatitude()) &&
|
|
||||||
(first.getLongitude() == second.getLongitude()) &&
|
|
||||||
(first.getAltitude() == second.getAltitude()) ) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Location location(String provider, double latitude, double longitude) {
|
private Location location(String provider, double latitude, double longitude) {
|
||||||
Location location = new Location(provider);
|
Location location = new Location(provider);
|
||||||
location.setLatitude(latitude);
|
location.setLatitude(latitude);
|
||||||
|
|
Loading…
Reference in a new issue