diff --git a/app/src/androidTest/java/ch/epfl/sdp/database/data_manager/HeatmapDataManagerTest.kt b/app/src/androidTest/java/ch/epfl/sdp/database/data_manager/HeatmapDataManagerTest.kt index 5de1e6088..eb335bbad 100644 --- a/app/src/androidTest/java/ch/epfl/sdp/database/data_manager/HeatmapDataManagerTest.kt +++ b/app/src/androidTest/java/ch/epfl/sdp/database/data_manager/HeatmapDataManagerTest.kt @@ -8,6 +8,8 @@ import ch.epfl.sdp.database.data.HeatmapPointData import ch.epfl.sdp.database.providers.HeatmapRepositoryProvider import ch.epfl.sdp.database.repository.IHeatmapRepository import ch.epfl.sdp.utils.Auth +import ch.epfl.sdp.utils.IdentifierUtils +import com.google.firebase.iid.FirebaseInstanceId import com.mapbox.mapboxsdk.geometry.LatLng import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.MatcherAssert.assertThat @@ -29,12 +31,14 @@ class HeatmapDataManagerTest { @Test fun addMeasureToHeatmapForNewHeatmapCallsUpdateHeatmap() { + val deviceId = IdentifierUtils.id() + Auth.accountId.value = DUMMY_HEATMAP_ID + val expectedHeatmapId = Auth.accountId.value + "__" + deviceId val expectedHeatMapData = HeatmapData(mutableListOf( HeatmapPointData(DUMMY_LOCATION, DUMMY_INTENSITY) - ), DUMMY_HEATMAP_ID) + ), expectedHeatmapId) val expectedGroupId = DUMMY_GROUP_ID - Auth.accountId.value = DUMMY_HEATMAP_ID val repo = Mockito.mock(IHeatmapRepository::class.java) Mockito.`when`(repo.getGroupHeatmaps(expectedGroupId)).thenReturn(MutableLiveData(mutableMapOf())) @@ -48,11 +52,15 @@ class HeatmapDataManagerTest { @Test fun addMeasureToHeatmapForExistingHeatmapCallsUpdateHeatmap() { + val deviceId = IdentifierUtils.id() + Auth.accountId.value = DUMMY_HEATMAP_ID + val expectedHeatmapId = Auth.accountId.value + "__" + deviceId + val expectedGroupId = DUMMY_GROUP_ID + val expectedHeatMapData = HeatmapData(mutableListOf( HeatmapPointData(DUMMY_LOCATION, DUMMY_INTENSITY) - ), DUMMY_HEATMAP_ID) - val expectedGroupId = DUMMY_GROUP_ID - val previousHeatMapData = HeatmapData(mutableListOf(), DUMMY_HEATMAP_ID) + ), expectedHeatmapId) + val previousHeatMapData = HeatmapData(mutableListOf(), expectedHeatmapId) Auth.accountId.value = DUMMY_HEATMAP_ID diff --git a/app/src/androidTest/java/ch/epfl/sdp/searcharea/QuadrilateralBuilderTest.kt b/app/src/androidTest/java/ch/epfl/sdp/searcharea/QuadrilateralBuilderTest.kt index c17853bc1..4dbfc7016 100644 --- a/app/src/androidTest/java/ch/epfl/sdp/searcharea/QuadrilateralBuilderTest.kt +++ b/app/src/androidTest/java/ch/epfl/sdp/searcharea/QuadrilateralBuilderTest.kt @@ -1,7 +1,6 @@ package ch.epfl.sdp.searcharea import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread import ch.epfl.sdp.utils.IntersectionUtils import com.mapbox.mapboxsdk.geometry.LatLng import org.hamcrest.CoreMatchers @@ -9,7 +8,6 @@ import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.junit.Rule import org.junit.Test -import timber.log.Timber import kotlin.random.Random class QuadrilateralBuilderTest { 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 8fae50c54..f3bae2955 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 @@ -38,13 +38,14 @@ import ch.epfl.sdp.database.repository.MarkerRepository import ch.epfl.sdp.database.repository.SearchGroupRepository import ch.epfl.sdp.database.repository.UserRepository import ch.epfl.sdp.drone.Drone +import ch.epfl.sdp.drone.DroneInstanceMock import ch.epfl.sdp.mission.SimpleQuadStrategy import ch.epfl.sdp.mission.SpiralStrategy import ch.epfl.sdp.searcharea.QuadrilateralArea -import ch.epfl.sdp.drone.DroneInstanceMock import ch.epfl.sdp.ui.maps.offline.OfflineManagerActivity import ch.epfl.sdp.utils.Auth import ch.epfl.sdp.utils.CentralLocationManager +import ch.epfl.sdp.utils.IdentifierUtils import com.mapbox.mapboxsdk.geometry.LatLng import org.hamcrest.CoreMatchers import org.hamcrest.Matchers.* @@ -183,6 +184,7 @@ class MapActivityTest { MainDataManager.groupId.value = DUMMY_GROUP_ID MainDataManager.role.value = Role.OPERATOR } + val expectedHeatmapId = Auth.accountId.value + "__" + IdentifierUtils.id() mActivityRule.launchActivity(Intent()) mUiDevice.wait(Until.hasObject(By.desc(applicationContext().getString(R.string.map_ready))), MAP_LOADING_TIMEOUT) @@ -196,10 +198,10 @@ class MapActivityTest { val heatmaps = mActivityRule.activity.heatmapManager.getGroupHeatmaps(DUMMY_GROUP_ID) assertThat(heatmaps.value, `is`(notNullValue())) - assertThat(heatmaps.value!![FAKE_ACCOUNT_ID], `is`(notNullValue())) - assertThat(heatmaps.value!![FAKE_ACCOUNT_ID]!!.value, `is`(notNullValue())) - assertThat(heatmaps.value!![FAKE_ACCOUNT_ID]!!.value!!.dataPoints, `is`(notNullValue())) - assertThat(heatmaps.value!![FAKE_ACCOUNT_ID]!!.value!!.dataPoints.size, equalTo(1)) + assertThat(heatmaps.value!![expectedHeatmapId], `is`(notNullValue())) + assertThat(heatmaps.value!![expectedHeatmapId]!!.value, `is`(notNullValue())) + assertThat(heatmaps.value!![expectedHeatmapId]!!.value!!.dataPoints, `is`(notNullValue())) + assertThat(heatmaps.value!![expectedHeatmapId]!!.value!!.dataPoints.size, equalTo(1)) } @Test diff --git a/app/src/main/java/ch/epfl/sdp/utils/IntersectionUtils.kt b/app/src/androidTest/java/ch/epfl/sdp/utils/IntersectionUtils.kt similarity index 100% rename from app/src/main/java/ch/epfl/sdp/utils/IntersectionUtils.kt rename to app/src/androidTest/java/ch/epfl/sdp/utils/IntersectionUtils.kt diff --git a/app/src/test/java/ch/epfl/sdp/IntersectionUtilsTest.kt b/app/src/androidTest/java/ch/epfl/sdp/utils/IntersectionUtilsTest.kt similarity index 98% rename from app/src/test/java/ch/epfl/sdp/IntersectionUtilsTest.kt rename to app/src/androidTest/java/ch/epfl/sdp/utils/IntersectionUtilsTest.kt index 53af420e6..feb6ad604 100644 --- a/app/src/test/java/ch/epfl/sdp/IntersectionUtilsTest.kt +++ b/app/src/androidTest/java/ch/epfl/sdp/utils/IntersectionUtilsTest.kt @@ -1,4 +1,4 @@ -package ch.epfl.sdp +package ch.epfl.sdp.utils import ch.epfl.sdp.utils.IntersectionUtils import com.mapbox.mapboxsdk.geometry.LatLng diff --git a/app/src/main/java/ch/epfl/sdp/database/data_manager/HeatmapDataManager.kt b/app/src/main/java/ch/epfl/sdp/database/data_manager/HeatmapDataManager.kt index 64f558d75..9718926d9 100644 --- a/app/src/main/java/ch/epfl/sdp/database/data_manager/HeatmapDataManager.kt +++ b/app/src/main/java/ch/epfl/sdp/database/data_manager/HeatmapDataManager.kt @@ -6,6 +6,7 @@ import ch.epfl.sdp.database.data.HeatmapData import ch.epfl.sdp.database.data.HeatmapPointData import ch.epfl.sdp.database.providers.HeatmapRepositoryProvider import ch.epfl.sdp.utils.Auth +import ch.epfl.sdp.utils.IdentifierUtils import com.mapbox.mapboxsdk.geometry.LatLng class HeatmapDataManager { @@ -13,7 +14,7 @@ class HeatmapDataManager { private val heatmapRepository = HeatmapRepositoryProvider.provide() fun addMeasureToHeatmap(groupId: String, location: LatLng, intensity: Double) { - val heatmapId = Auth.accountId.value + val heatmapId = Auth.accountId.value + "__" + IdentifierUtils.id() val heatmaps = heatmapRepository.getGroupHeatmaps(groupId).value val heatmapData = if (heatmaps != null && heatmaps.containsKey(heatmapId)) { diff --git a/app/src/main/java/ch/epfl/sdp/utils/IdentifierUtils.kt b/app/src/main/java/ch/epfl/sdp/utils/IdentifierUtils.kt new file mode 100644 index 000000000..fce6b7bb7 --- /dev/null +++ b/app/src/main/java/ch/epfl/sdp/utils/IdentifierUtils.kt @@ -0,0 +1,27 @@ +package ch.epfl.sdp.utils + +import android.content.Context.MODE_PRIVATE +import android.content.SharedPreferences +import ch.epfl.sdp.MainApplication +import java.util.* + +object IdentifierUtils { + private var uniqueID: String? = null + private const val PREF_UNIQUE_ID = "PREF_UNIQUE_ID" + + @Synchronized + fun id(): String { + if (uniqueID == null) { + val sharedPrefs: SharedPreferences = MainApplication.applicationContext().getSharedPreferences( + PREF_UNIQUE_ID, MODE_PRIVATE) + uniqueID = sharedPrefs.getString(PREF_UNIQUE_ID, null) + if (uniqueID == null) { + uniqueID = UUID.randomUUID().toString() + val editor: SharedPreferences.Editor = sharedPrefs.edit() + editor.putString(PREF_UNIQUE_ID, uniqueID) + editor.apply() + } + } + return uniqueID!! + } +} \ No newline at end of file