From 8aa0c856ab14f9c421c9675d12fc5c02c72205be Mon Sep 17 00:00:00 2001 From: Andrei Bechet Date: Tue, 16 Jun 2015 11:25:37 +0200 Subject: [PATCH] Refactoring the LocationProvider test of latestLocation --- .../java/esrlabs/com/geofence/MyService.java | 2 +- .../java/esrlabs.com.geofence/MyServiceTest.java | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/2015/android/Geofence/app/src/main/java/esrlabs/com/geofence/MyService.java b/2015/android/Geofence/app/src/main/java/esrlabs/com/geofence/MyService.java index 566f842..c790346 100644 --- a/2015/android/Geofence/app/src/main/java/esrlabs/com/geofence/MyService.java +++ b/2015/android/Geofence/app/src/main/java/esrlabs/com/geofence/MyService.java @@ -62,4 +62,4 @@ public class MyService extends Service implements LocationListener { public void onProviderDisabled(String s) {} @Override public void onProviderEnabled(String s) {} -} +} \ No newline at end of file diff --git a/2015/android/Geofence/app/src/test/java/esrlabs.com.geofence/MyServiceTest.java b/2015/android/Geofence/app/src/test/java/esrlabs.com.geofence/MyServiceTest.java index 90d651e..c70e331 100644 --- a/2015/android/Geofence/app/src/test/java/esrlabs.com.geofence/MyServiceTest.java +++ b/2015/android/Geofence/app/src/test/java/esrlabs.com.geofence/MyServiceTest.java @@ -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);