From 198dbd6389b52dfa8812610ab489b2c03a0884a6 Mon Sep 17 00:00:00 2001 From: Sufyan Abbasi Date: Thu, 7 Mar 2024 18:27:59 -0800 Subject: [PATCH] Add License and code cleanup. --- .../persistence/local/LocalDataStoreTests.kt | 41 ++++++++++--------- .../schema/LoiMutationConverterTest.kt | 16 ++++++++ .../main/kotlin/com/sharedtest/FakeData.kt | 24 ++++++----- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/ground/src/test/java/com/google/android/ground/persistence/local/LocalDataStoreTests.kt b/ground/src/test/java/com/google/android/ground/persistence/local/LocalDataStoreTests.kt index 3d68a39b6d..5bf938edf9 100644 --- a/ground/src/test/java/com/google/android/ground/persistence/local/LocalDataStoreTests.kt +++ b/ground/src/test/java/com/google/android/ground/persistence/local/LocalDataStoreTests.kt @@ -111,7 +111,7 @@ class LocalDataStoreTests : BaseHiltTest() { @Test fun testInsertAndGetUser() = runWithTestDispatcher { localUserStore.insertOrUpdateUser(TEST_USER) - assertThat(localUserStore.getUser("user id")).isEqualTo(TEST_USER) + assertThat(localUserStore.getUser(FakeData.USER_ID)).isEqualTo(TEST_USER) } @Test @@ -174,7 +174,7 @@ class LocalDataStoreTests : BaseHiltTest() { localSurveyStore.insertOrUpdateSurvey(TEST_SURVEY) localLoiStore.applyAndEnqueue(TEST_LOI_MUTATION) - val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id") + val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID) localLoiStore.findLocationsOfInterest(TEST_SURVEY).test { assertThat(expectMostRecentItem()).isEqualTo(setOf(loi)) @@ -186,10 +186,10 @@ class LocalDataStoreTests : BaseHiltTest() { localUserStore.insertOrUpdateUser(TEST_USER) localSurveyStore.insertOrUpdateSurvey(TEST_SURVEY) localLoiStore.applyAndEnqueue(TEST_LOI_MUTATION) - val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")!! + val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)!! val newLoi = loi.copy(geometry = TEST_POINT_2) localLoiStore.merge(newLoi) - val newLoi2 = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id") + val newLoi2 = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID) assertThat(newLoi2?.geometry).isEqualTo(TEST_POINT_2) } @@ -198,10 +198,10 @@ class LocalDataStoreTests : BaseHiltTest() { localUserStore.insertOrUpdateUser(TEST_USER) localSurveyStore.insertOrUpdateSurvey(TEST_SURVEY) localLoiStore.applyAndEnqueue(TEST_POLYGON_LOI_MUTATION) - val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")!! + val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)!! val newLoi = loi.copy(geometry = Polygon(LinearRing(TEST_POLYGON_2))) localLoiStore.merge(newLoi) - val newLoi2 = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id") + val newLoi2 = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID) assertThat(newLoi2?.geometry?.getShellCoordinates()).isEqualTo(TEST_POLYGON_2) } @@ -220,7 +220,7 @@ class LocalDataStoreTests : BaseHiltTest() { MutationEntitySyncStatus.PENDING ) .test { assertThat(expectMostRecentItem()).isEqualTo(listOf(TEST_SUBMISSION_MUTATION)) } - val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")!! + val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)!! var submission = localSubmissionStore.getSubmission(loi, "submission id") assertEquivalent(TEST_SUBMISSION_MUTATION, submission) @@ -253,7 +253,7 @@ class LocalDataStoreTests : BaseHiltTest() { assertEquivalent(mutation, submission) // also test that getSubmissions returns the same submission as well - val submissions = localSubmissionStore.getSubmissions(loi, "job id") + val submissions = localSubmissionStore.getSubmissions(loi, FakeData.JOB_ID) assertThat(submissions).hasSize(1) assertEquivalent(mutation, submissions[0]) } @@ -264,7 +264,7 @@ class LocalDataStoreTests : BaseHiltTest() { localSurveyStore.insertOrUpdateSurvey(TEST_SURVEY) localLoiStore.applyAndEnqueue(TEST_LOI_MUTATION) localSubmissionStore.applyAndEnqueue(TEST_SUBMISSION_MUTATION) - val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")!! + val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)!! val data = SubmissionData(mapOf(Pair("task id", TextResponse.fromString("foo value")))) val submission = localSubmissionStore.getSubmission(loi, "submission id").copy(data = data) localSubmissionStore.merge(submission) @@ -288,7 +288,7 @@ class LocalDataStoreTests : BaseHiltTest() { assertThat(submissionDao.findById("submission id")?.state).isEqualTo(EntityState.DELETED) // Verify that the local submission doesn't end up in getSubmissions(). - val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")!! + val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)!! assertThat(localSubmissionStore.getSubmissions(loi, "task id")).isEmpty() // After successful remote sync, delete submission is called by LocalMutationSyncWorker. @@ -308,7 +308,7 @@ class LocalDataStoreTests : BaseHiltTest() { localSubmissionStore.applyAndEnqueue(TEST_SUBMISSION_MUTATION) // Assert that one LOI is streamed. - val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")!! + val loi = localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)!! localLoiStore.findLocationsOfInterest(TEST_SURVEY).test { assertThat(expectMostRecentItem()).isEqualTo(setOf(loi)) } @@ -318,7 +318,8 @@ class LocalDataStoreTests : BaseHiltTest() { localLoiStore.applyAndEnqueue(mutation) // Verify that local entity exists but its state is updated to DELETED. - assertThat(locationOfInterestDao.findById("loi id")?.state).isEqualTo(EntityState.DELETED) + assertThat(locationOfInterestDao.findById(FakeData.LOI_ID)?.state) + .isEqualTo(EntityState.DELETED) // Verify that the local LOI is now removed from the latest LOI stream. localLoiStore.findLocationsOfInterest(TEST_SURVEY).test { @@ -326,10 +327,10 @@ class LocalDataStoreTests : BaseHiltTest() { } // After successful remote sync, delete LOI is called by LocalMutationSyncWorker. - localLoiStore.deleteLocationOfInterest("loi id") + localLoiStore.deleteLocationOfInterest(FakeData.LOI_ID) // Verify that the LOI doesn't exist anymore - assertThat(localLoiStore.getLocationOfInterest(TEST_SURVEY, "loi id")).isNull() + assertThat(localLoiStore.getLocationOfInterest(TEST_SURVEY, FakeData.LOI_ID)).isNull() // Verify that the linked submission is also deleted. assertFailsWith { @@ -373,13 +374,13 @@ class LocalDataStoreTests : BaseHiltTest() { } companion object { - private val TEST_USER = User("user id", "user@gmail.com", "user 1") + private val TEST_USER = User(FakeData.USER_ID, "user@gmail.com", "user 1") private val TEST_TASK = Task("task id", 1, Task.Type.TEXT, "task label", false) private val TEST_STYLE = Style("#112233") private val TEST_JOB = - Job("job id", TEST_STYLE, "heading title", mapOf(Pair(TEST_TASK.id, TEST_TASK))) + Job(FakeData.JOB_ID, TEST_STYLE, "heading title", mapOf(Pair(TEST_TASK.id, TEST_TASK))) private val TEST_SURVEY = - Survey("survey id", "survey 1", "foo description", mapOf(Pair(TEST_JOB.id, TEST_JOB))) + Survey(FakeData.SURVEY_ID, "survey 1", "foo description", mapOf(Pair(TEST_JOB.id, TEST_JOB))) private val TEST_SURVEY_WITH_TILE_SOURCES = TEST_SURVEY.copy( tileSources = @@ -419,9 +420,9 @@ class LocalDataStoreTests : BaseHiltTest() { id = 1L, type = Mutation.Type.CREATE, syncStatus = SyncStatus.PENDING, - surveyId = "survey id", - locationOfInterestId = "loi id", - userId = "user id" + surveyId = FakeData.SURVEY_ID, + locationOfInterestId = FakeData.LOI_ID, + userId = FakeData.USER_ID ) private val TEST_OFFLINE_AREA = OfflineArea("id_1", OfflineArea.State.PENDING, Bounds(0.0, 0.0, 0.0, 0.0), "Test Area", 0..14) diff --git a/ground/src/test/java/com/google/android/ground/persistence/remote/firebase/schema/LoiMutationConverterTest.kt b/ground/src/test/java/com/google/android/ground/persistence/remote/firebase/schema/LoiMutationConverterTest.kt index 15526b61b3..12da7f5841 100644 --- a/ground/src/test/java/com/google/android/ground/persistence/remote/firebase/schema/LoiMutationConverterTest.kt +++ b/ground/src/test/java/com/google/android/ground/persistence/remote/firebase/schema/LoiMutationConverterTest.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.android.ground.persistence.remote.firebase.schema import com.google.android.ground.model.geometry.Coordinates diff --git a/sharedTest/src/main/kotlin/com/sharedtest/FakeData.kt b/sharedTest/src/main/kotlin/com/sharedtest/FakeData.kt index c703aa064a..b04e03d208 100644 --- a/sharedTest/src/main/kotlin/com/sharedtest/FakeData.kt +++ b/sharedTest/src/main/kotlin/com/sharedtest/FakeData.kt @@ -44,6 +44,10 @@ object FakeData { // TODO: Replace constants with calls to newFoo() methods. val TERMS_OF_SERVICE: TermsOfService = TermsOfService("TERMS_OF_SERVICE", "Fake Terms of Service text") + const val JOB_ID = "job id" + const val LOI_ID = "loi id" + const val USER_ID = "user id" + const val SURVEY_ID = "survey id" val JOB = Job( @@ -67,7 +71,7 @@ object FakeData { val LOCATION_OF_INTEREST = LocationOfInterest( - "loi id", + LOI_ID, SURVEY.id, JOB, customId = "", @@ -99,7 +103,7 @@ object FakeData { val AREA_OF_INTEREST: LocationOfInterest = LocationOfInterest( - "loi id", + LOI_ID, SURVEY.id, JOB, "", @@ -142,14 +146,14 @@ object FakeData { syncStatus: Mutation.SyncStatus = Mutation.SyncStatus.PENDING, ): LocationOfInterestMutation = LocationOfInterestMutation( - jobId = "job id", + jobId = JOB_ID, geometry = point, id = 1L, - locationOfInterestId = "loi id", + locationOfInterestId = LOI_ID, type = mutationType, syncStatus = syncStatus, - userId = "user id", - surveyId = "survey id", + userId = USER_ID, + surveyId = SURVEY_ID, clientTimestamp = Date() ) @@ -159,14 +163,14 @@ object FakeData { syncStatus: Mutation.SyncStatus = Mutation.SyncStatus.PENDING, ): LocationOfInterestMutation = LocationOfInterestMutation( - jobId = "job id", + jobId = JOB_ID, geometry = Polygon(LinearRing(polygonVertices)), id = 1L, - locationOfInterestId = "loi id", + locationOfInterestId = LOI_ID, type = mutationType, syncStatus = syncStatus, - userId = "user id", - surveyId = "survey id", + userId = USER_ID, + surveyId = SURVEY_ID, clientTimestamp = Date() ) }