From 913174fffedbcc8f2224e7dfdbc7136dedb3e5e6 Mon Sep 17 00:00:00 2001 From: Nolan Chappuis Date: Fri, 5 Jun 2020 15:46:19 +0200 Subject: [PATCH 1/8] Remove useless test --- .../ch/epfl/sdp/ui/maps/MapActivityTest.kt | 26 ------------------- .../sdp/utils/LocationWithPermissionTest.kt | 18 +++++++++++++ 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt b/app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt index 1dc8a59c5..96cbc755a 100644 --- a/app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt +++ b/app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt @@ -238,32 +238,6 @@ class MapActivityTest { HeatmapRepository.daoProvider = { OfflineHeatmapDao() } } - @Test - fun canUpdateUserLocation() { - //TODO Rewrite this test - CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST) - } - - @Test - fun canUpdateUserLocationTwice() { - //TODO Rewrite this test - CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST) - CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST) - } - - @Test - fun canOnRequestPermissionResult() { - //TODO Rewrite this test - runOnUiThread { - MainDataManager.goOffline() - MainDataManager.groupId.value = DUMMY_GROUP_ID - MainDataManager.role.value = Role.OPERATOR - } - mActivityRule.launchActivity(Intent()) - - mActivityRule.activity.onRequestPermissionsResult(1011, Array(0) { "" }, IntArray(0)) - } - @Test fun droneStatusIsVisibleForOperator() { runOnUiThread { diff --git a/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt b/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt index 7de368a5a..dcd243e5a 100644 --- a/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt +++ b/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt @@ -23,6 +23,8 @@ import ch.epfl.sdp.database.repository.HeatmapRepository import ch.epfl.sdp.database.repository.MarkerRepository import ch.epfl.sdp.ui.drone.DroneInstanceMock import ch.epfl.sdp.ui.maps.MapActivity +import ch.epfl.sdp.ui.maps.MapActivityTest +import com.mapbox.mapboxsdk.geometry.LatLng import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.MatcherAssert.assertThat import org.junit.Before @@ -38,6 +40,7 @@ class LocationWithPermissionTest { private var mUiDevice: UiDevice? = null companion object { + private val FAKE_LOCATION_TEST = LatLng(42.125, -30.229) private const val DUMMY_GROUP_ID = "DummyGroupId" private const val FAKE_ACCOUNT_ID = "fake_account_id" private const val REFRESH_RATE = 500L @@ -102,4 +105,19 @@ class LocationWithPermissionTest { CentralLocationManager.onRequestPermissionsResult(1011, Array(0) { "" }, IntArray(0)) Mockito.verify(manager, Mockito.times(2)).requestLocationUpdates(Mockito.eq(LocationManager.GPS_PROVIDER), Mockito.eq(REFRESH_RATE), Mockito.eq(MIN_DIST), Mockito.any()) } + + + @Test + fun canUpdateUserLocation() { + //TODO Rewrite this test + CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST) + } + + @Test + fun canUpdateUserLocationTwice() { + //TODO Rewrite this test + CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST) + CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST) + } + } From 8b2b10deebd295924b295a27ed1e9f080ed916d0 Mon Sep 17 00:00:00 2001 From: Nolan Chappuis Date: Fri, 5 Jun 2020 15:47:32 +0200 Subject: [PATCH 2/8] Remove useless tests --- .../epfl/sdp/utils/LocationWithPermissionTest.kt | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt b/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt index dcd243e5a..323a3d097 100644 --- a/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt +++ b/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt @@ -106,18 +106,4 @@ class LocationWithPermissionTest { Mockito.verify(manager, Mockito.times(2)).requestLocationUpdates(Mockito.eq(LocationManager.GPS_PROVIDER), Mockito.eq(REFRESH_RATE), Mockito.eq(MIN_DIST), Mockito.any()) } - - @Test - fun canUpdateUserLocation() { - //TODO Rewrite this test - CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST) - } - - @Test - fun canUpdateUserLocationTwice() { - //TODO Rewrite this test - CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST) - CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST) - } - } From 27a4d76aeaac9b8e095c0fd7aca7faf4d7cf640d Mon Sep 17 00:00:00 2001 From: Nolan Chappuis Date: Fri, 5 Jun 2020 16:05:10 +0200 Subject: [PATCH 3/8] Add test missionStartWithClosestPoint --- .../sdp/mission/SimpleQuadStrategyTest.kt | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/test/java/ch/epfl/sdp/mission/SimpleQuadStrategyTest.kt b/app/src/test/java/ch/epfl/sdp/mission/SimpleQuadStrategyTest.kt index 2a63a6735..dc1983a54 100644 --- a/app/src/test/java/ch/epfl/sdp/mission/SimpleQuadStrategyTest.kt +++ b/app/src/test/java/ch/epfl/sdp/mission/SimpleQuadStrategyTest.kt @@ -2,8 +2,8 @@ package ch.epfl.sdp.mission import ch.epfl.sdp.searcharea.QuadrilateralArea import com.mapbox.mapboxsdk.geometry.LatLng +import net.mastrgamr.mbmapboxutils.SphericalUtil.computeOffset import org.hamcrest.CoreMatchers.equalTo -import net.mastrgamr.mbmapboxutils.SphericalUtil.* import org.hamcrest.MatcherAssert.assertThat import org.junit.Test import java.lang.Double.max @@ -76,5 +76,21 @@ class SimpleQuadStrategyTest { assertThat("Wanted $theoryRes, but got: $res", diff < 0.01) } - //TODO test that starting location is taken into account. + @Test + fun missionStartsWithClosestPoint() { + val waypoints = arrayListOf( + LatLng(47.397026, 8.543067), //we consider the closest point to the drone + LatLng(47.398979, 8.543434), + LatLng(47.398279, 8.543934), + LatLng(47.397426, 8.544867) + ) + + val searchArea = QuadrilateralArea(waypoints + ) + val dronePos = LatLng(47.4, 8.6) + val strategy = SimpleQuadStrategy(20.0) + val path = strategy.createFlightPath(dronePos, searchArea) + val orderedSearchArea = waypoints.sortedBy { it.distanceTo(dronePos) } + assertThat(path[0], equalTo(orderedSearchArea[0])) + } } \ No newline at end of file From 6bbfb455c578d387cb563493ad4cb534622021c0 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Jun 2020 17:47:11 +0200 Subject: [PATCH 4/8] Remove useless TODO --- .../ch/epfl/sdp/ui/maps/offline/OfflineManagerActivityTest.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/androidTest/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivityTest.kt b/app/src/androidTest/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivityTest.kt index 6cb624072..e9dcf368b 100644 --- a/app/src/androidTest/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivityTest.kt +++ b/app/src/androidTest/java/ch/epfl/sdp/ui/maps/offline/OfflineManagerActivityTest.kt @@ -31,8 +31,6 @@ import org.junit.runner.RunWith import java.util.concurrent.CountDownLatch import java.util.concurrent.TimeUnit - -//TODO extract toast tests (now commented) @RunWith(AndroidJUnit4::class) class OfflineManagerActivityTest { private lateinit var mUiDevice: UiDevice From c62d72dd9f30244f505efb1bf452c65f8d20f3a8 Mon Sep 17 00:00:00 2001 From: Nolan Chappuis Date: Fri, 5 Jun 2020 19:19:53 +0200 Subject: [PATCH 5/8] Remove useless companion object --- .../java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt b/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt index 323a3d097..cd62fac0e 100644 --- a/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt +++ b/app/src/androidTest/java/ch/epfl/sdp/utils/LocationWithPermissionTest.kt @@ -40,7 +40,6 @@ class LocationWithPermissionTest { private var mUiDevice: UiDevice? = null companion object { - private val FAKE_LOCATION_TEST = LatLng(42.125, -30.229) private const val DUMMY_GROUP_ID = "DummyGroupId" private const val FAKE_ACCOUNT_ID = "fake_account_id" private const val REFRESH_RATE = 500L From a6b28e0ec11f9486f10619f45e5d9dc9d3040914 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Jun 2020 19:47:16 +0200 Subject: [PATCH 6/8] Semi-Implment --- app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt b/app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt index c7340c919..ebb97a3b2 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt @@ -130,7 +130,6 @@ class MapActivity : MapViewBaseActivity(), OnMapReadyCallback, MapboxMap.OnMapLo super.initMapView(savedInstanceState, R.layout.activity_map, R.id.mapView) mapView.getMapAsync(this) - //TODO: Give user location if current drone position is not available CentralLocationManager.configure(this) mapView.contentDescription = getString(R.string.map_not_ready) @@ -305,7 +304,8 @@ class MapActivity : MapViewBaseActivity(), OnMapReadyCallback, MapboxMap.OnMapLo } else if (!searchAreaBuilder.isComplete()) { //TODO add missionBuilder isComplete method Toast.makeText(this, getString(R.string.not_enough_waypoints_message), Toast.LENGTH_SHORT).show() } else { - launchMission() + val mission = missionBuilder.build() + launchMission(mission) } } @@ -314,10 +314,10 @@ class MapActivity : MapViewBaseActivity(), OnMapReadyCallback, MapboxMap.OnMapLo } @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) - fun launchMission() { + fun launchMission(mission: List) { val altitude = PreferenceManager.getDefaultSharedPreferences(this) .getString(this.getString(R.string.pref_key_drone_altitude), Drone.DEFAULT_ALTITUDE.toString()).toString().toFloat() - Drone.startMission(DroneUtils.makeDroneMission(missionBuilder.build(), altitude), groupId.value!!) + Drone.startMission(DroneUtils.makeDroneMission(mission, altitude), groupId.value!!) searchAreaBuilder.reset() } From 270812bd416efb666cdc2628f6a75b50340d93f9 Mon Sep 17 00:00:00 2001 From: Nolan Chappuis Date: Fri, 5 Jun 2020 20:01:08 +0200 Subject: [PATCH 7/8] Correct launch mission from clickingOnLaunchMissionStartAndGenerateAMission --- .../java/ch/epfl/sdp/ui/maps/MapActivityTest.kt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt b/app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt index 2b3e65fbb..8d1ad3f3a 100644 --- a/app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt +++ b/app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt @@ -125,7 +125,6 @@ class MapActivityTest { mUiDevice.wait(Until.hasObject(By.desc(applicationContext().getString(R.string.map_ready))), MAP_LOADING_TIMEOUT) assertThat(mActivityRule.activity.mapView.contentDescription == applicationContext().getString(R.string.map_ready), equalTo(true)) - runOnUiThread { val searchArea = QuadrilateralArea(arrayListOf( LatLng(47.397026, 8.543067), //we consider the closest point to the drone @@ -133,16 +132,13 @@ class MapActivityTest { LatLng(47.398279, 8.543934), LatLng(47.397426, 8.544867) )) - mActivityRule.activity.missionBuilder + val mission = mActivityRule.activity.missionBuilder .withSearchArea(searchArea) .withStartingLocation(LatLng(47.397026, 8.543067)) - .withStrategy(SimpleQuadStrategy(Drone.GROUND_SENSOR_SCOPE)) + .withStrategy(SimpleQuadStrategy(Drone.GROUND_SENSOR_SCOPE)).build() + mActivityRule.activity.launchMission(mission) } - // Then start mission officially - runOnUiThread { - mActivityRule.activity.launchMission() - } val uploadedMission = Drone.missionLiveData.value assertThat(uploadedMission, `is`(notNullValue())) From c96c53ef2e5329dd890d771ad9d1957579e6fec0 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 5 Jun 2020 21:30:38 +0200 Subject: [PATCH 8/8] Remove TODO from implemented method --- app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt b/app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt index ebb97a3b2..f51fa5708 100644 --- a/app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt +++ b/app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt @@ -301,7 +301,7 @@ class MapActivity : MapViewBaseActivity(), OnMapReadyCallback, MapboxMap.OnMapLo fun startOrPauseMissionButton(v: View) { if (Drone.isFlyingLiveData.value!!) { if (Drone.isMissionPausedLiveData.value!!) Drone.resumeMission() else Drone.pauseMission() - } else if (!searchAreaBuilder.isComplete()) { //TODO add missionBuilder isComplete method + } else if (!searchAreaBuilder.isComplete()) { Toast.makeText(this, getString(R.string.not_enough_waypoints_message), Toast.LENGTH_SHORT).show() } else { val mission = missionBuilder.build()