Refactoring the LocationProvider test of latestLocation

This commit is contained in:
Andrei Bechet 2015-06-16 11:25:37 +02:00
parent 6a2eddeea6
commit 8aa0c856ab
2 changed files with 3 additions and 15 deletions

View file

@ -41,13 +41,12 @@ public class MyServiceTest extends ServiceTestCase {
MyService mainService = setupMyService(locationManager);
simulateNewLocation(locationManager);
assertTrue(areTheLocationsEqual(someLocation, mainService.latestLocation()));
assertTrue(someLocation.equals(mainService.latestLocation()));
}
private void simulateNewLocation(LocationManager locationManager) {
ShadowLocationManager shadowLocationManager = Shadows.shadowOf(locationManager);
shadowLocationManager.simulateLocation(location(CAN_PROVIDER,
someLocation.getLatitude(), someLocation.getLongitude()));
shadowLocationManager.simulateLocation(someLocation);
}
private MyService setupMyService(LocationManager locationManager) {
@ -56,17 +55,6 @@ public class MyServiceTest extends ServiceTestCase {
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) {
Location location = new Location(provider);
location.setLatitude(latitude);