Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into refactor/mapTests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0tonic authored Jun 5, 2020
2 parents c96c53e + 6fc56db commit cffcb61
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()))
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
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
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 {
Expand Down
12 changes: 7 additions & 5 deletions app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -179,6 +180,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)
Expand All @@ -192,10 +194,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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ 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 {

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)) {
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/ch/epfl/sdp/utils/IdentifierUtils.kt
Original file line number Diff line number Diff line change
@@ -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!!
}
}

0 comments on commit cffcb61

Please sign in to comment.