diff --git a/feature/client-api/src/test/java/com/simprints/feature/clientapi/ClientApiViewModelTest.kt b/feature/client-api/src/test/java/com/simprints/feature/clientapi/ClientApiViewModelTest.kt index 8e67cf07ea..f01529702e 100644 --- a/feature/client-api/src/test/java/com/simprints/feature/clientapi/ClientApiViewModelTest.kt +++ b/feature/client-api/src/test/java/com/simprints/feature/clientapi/ClientApiViewModelTest.kt @@ -157,7 +157,7 @@ internal class ClientApiViewModelTest { deleteSessionEventsIfNeeded(any()) persistentLogger.log(any(), any(), any(), any()) } - verify { resultMapper.invoke(withArg { it is ActionResponse.EnrolActionResponse }) } + verify { resultMapper.invoke(match { it is ActionResponse.EnrolActionResponse }) } viewModel.returnResponse.test().assertHasValue() } @@ -172,7 +172,7 @@ internal class ClientApiViewModelTest { simpleEventReporter.addCompletionCheckEvent(eq(true)) persistentLogger.log(any(), any(), any(), any()) } - verify { resultMapper.invoke(withArg { it is ActionResponse.IdentifyActionResponse }) } + verify { resultMapper.invoke(match { it is ActionResponse.IdentifyActionResponse }) } viewModel.returnResponse.test().assertHasValue() } @@ -188,7 +188,7 @@ internal class ClientApiViewModelTest { deleteSessionEventsIfNeeded(any()) persistentLogger.log(any(), any(), any(), any()) } - verify { resultMapper.invoke(withArg { it is ActionResponse.ConfirmActionResponse }) } + verify { resultMapper.invoke(match { it is ActionResponse.ConfirmActionResponse }) } viewModel.returnResponse.test().assertHasValue() } @@ -205,7 +205,7 @@ internal class ClientApiViewModelTest { deleteSessionEventsIfNeeded(any()) persistentLogger.log(any(), any(), any(), any()) } - verify { resultMapper.invoke(withArg { it is ActionResponse.VerifyActionResponse }) } + verify { resultMapper.invoke(match { it is ActionResponse.VerifyActionResponse }) } viewModel.returnResponse.test().assertHasValue() } @@ -225,7 +225,7 @@ internal class ClientApiViewModelTest { deleteSessionEventsIfNeeded(any()) persistentLogger.log(any(), any(), any(), any()) } - verify { resultMapper.invoke(withArg { it is ActionResponse.ExitFormActionResponse }) } + verify { resultMapper.invoke(match { it is ActionResponse.ExitFormActionResponse }) } viewModel.returnResponse.test().assertHasValue() } @@ -242,7 +242,7 @@ internal class ClientApiViewModelTest { deleteSessionEventsIfNeeded(any()) persistentLogger.log(any(), any(), any(), any()) } - verify { resultMapper.invoke(withArg { it is ActionResponse.ErrorActionResponse }) } + verify { resultMapper.invoke(match { it is ActionResponse.ErrorActionResponse }) } viewModel.returnResponse.test().assertHasValue() } diff --git a/infra/enrolment-records/repository/src/test/java/com/simprints/infra/enrolment/records/repository/local/RealmEnrolmentRecordLocalDataSourceTest.kt b/infra/enrolment-records/repository/src/test/java/com/simprints/infra/enrolment/records/repository/local/RealmEnrolmentRecordLocalDataSourceTest.kt index 4da9160435..8508074a68 100644 --- a/infra/enrolment-records/repository/src/test/java/com/simprints/infra/enrolment/records/repository/local/RealmEnrolmentRecordLocalDataSourceTest.kt +++ b/infra/enrolment-records/repository/src/test/java/com/simprints/infra/enrolment/records/repository/local/RealmEnrolmentRecordLocalDataSourceTest.kt @@ -267,13 +267,15 @@ class RealmEnrolmentRecordLocalDataSourceTest { @Test fun performSubjectCreationAction_deletesOldSamples() = runTest { + val faceReferenceId = "faceToDelete" + val fingerReferenceId = "fingerToDelete" every { realmSingleQuery.find() } returns getRandomSubject() .copy( faceSamples = listOf( - getRandomFaceSample("faceToDelete"), + getRandomFaceSample(referenceId = faceReferenceId), ), fingerprintSamples = listOf( - getRandomFingerprintSample("fingerToDelete"), + getRandomFingerprintSample(referenceId = fingerReferenceId), ), ).toRealmDb() val subject = getFakePerson() @@ -284,8 +286,8 @@ class RealmEnrolmentRecordLocalDataSourceTest { ) verify { - mutableRealm.delete(withArg { it.id == "faceToDelete" }) - mutableRealm.delete(withArg { it.id == "faceToDelete" }) + mutableRealm.delete(match { it.referenceId == faceReferenceId }) + mutableRealm.delete(match { it.referenceId == fingerReferenceId }) } val peopleCount = enrolmentRecordLocalDataSource.count() assertThat(peopleCount).isEqualTo(1) @@ -294,13 +296,15 @@ class RealmEnrolmentRecordLocalDataSourceTest { @Test fun performSubjectUpdateAction() = runTest { val subject = getFakePerson() + val faceReferenceId = "faceToDelete" + val fingerReferenceId = "fingerToDelete" every { realmSingleQuery.find() } returns getRandomSubject( faceSamples = listOf( - getRandomFaceSample(referenceId = "faceToDelete"), + getRandomFaceSample(referenceId = faceReferenceId), getRandomFaceSample(), ), fingerprintSamples = listOf( - getRandomFingerprintSample(referenceId = "fingerToDelete"), + getRandomFingerprintSample(referenceId = fingerReferenceId), getRandomFingerprintSample(), ), ).toRealmDb() @@ -311,7 +315,7 @@ class RealmEnrolmentRecordLocalDataSourceTest { subject.subjectId.toString(), faceSamplesToAdd = listOf(getRandomFaceSample()), fingerprintSamplesToAdd = listOf(getRandomFingerprintSample()), - referenceIdsToRemove = listOf("faceToDelete", "fingerToDelete"), + referenceIdsToRemove = listOf(faceReferenceId, fingerReferenceId), ), ), project, @@ -319,15 +323,15 @@ class RealmEnrolmentRecordLocalDataSourceTest { val peopleCount = enrolmentRecordLocalDataSource.count() assertThat(peopleCount).isEqualTo(1) verify { - mutableRealm.delete(withArg { it.id == "faceToDelete" }) - mutableRealm.delete(withArg { it.id == "faceToDelete" }) + mutableRealm.delete(match { it.referenceId == faceReferenceId }) + mutableRealm.delete(match { it.referenceId == fingerReferenceId }) mutableRealm.copyToRealm( - withArg { + match { // one old + one new it.faceSamples.size == 2 && - it.fingerprintSamples.size == 2 && - it.faceSamples.none { it.referenceId == "faceToDelete" } && - it.fingerprintSamples.none { it.referenceId == "fingerToDelete" } + it.fingerprintSamples.size == 2 && + it.faceSamples.none { sample -> sample.referenceId == faceReferenceId } && + it.fingerprintSamples.none { sample -> sample.referenceId == fingerReferenceId } }, any(), ) @@ -368,7 +372,6 @@ class RealmEnrolmentRecordLocalDataSourceTest { assertThat(peopleCount).isEqualTo(0) } - @OptIn(ExperimentalCoroutinesApi::class) @Test fun `loadAllSubjectsInBatches with no subjects should return empty list and close channel`() = runTest { val batchSize = 10 diff --git a/infra/event-sync/src/test/java/com/simprints/infra/eventsync/sync/down/tasks/EventDownSyncTaskTest.kt b/infra/event-sync/src/test/java/com/simprints/infra/eventsync/sync/down/tasks/EventDownSyncTaskTest.kt index ce832d5650..a7d6b01de8 100644 --- a/infra/event-sync/src/test/java/com/simprints/infra/eventsync/sync/down/tasks/EventDownSyncTaskTest.kt +++ b/infra/event-sync/src/test/java/com/simprints/infra/eventsync/sync/down/tasks/EventDownSyncTaskTest.kt @@ -10,8 +10,8 @@ import com.simprints.infra.config.store.models.Project import com.simprints.infra.config.sync.ConfigManager import com.simprints.infra.enrolment.records.repository.EnrolmentRecordRepository import com.simprints.infra.enrolment.records.repository.domain.models.Subject -import com.simprints.infra.enrolment.records.repository.domain.models.SubjectAction.Creation -import com.simprints.infra.enrolment.records.repository.domain.models.SubjectAction.Deletion +import com.simprints.infra.enrolment.records.repository.domain.models.SubjectAction +import com.simprints.infra.enrolment.records.repository.domain.models.SubjectAction.* import com.simprints.infra.events.EventRepository import com.simprints.infra.events.event.domain.models.downsync.EventDownSyncRequestEvent import com.simprints.infra.events.event.domain.models.scope.EventScope @@ -509,7 +509,7 @@ class EventDownSyncTaskTest { } @Test - fun downSync_shouldProcessRecordUpdateEvent_withCreations() = runTest { + fun downSync_shouldProcessRecordUpdateEvent_withUpdate() = runTest { coEvery { enrolmentRecordRepository.load(any()) } returns listOf( Subject( subjectId = "subjectId", @@ -529,34 +529,9 @@ class EventDownSyncTaskTest { coVerify { enrolmentRecordRepository.performActions( - withArg { actions -> actions.all { it is Creation } }, - any(), - ) - } - } - - @Test - fun downSync_shouldProcessRecordUpdateEvent_withDeletions() = runTest { - coEvery { enrolmentRecordRepository.load(any()) } returns listOf( - Subject( - subjectId = "subjectId", - projectId = "projectId", - attendantId = "moduleId".asTokenizableRaw(), - moduleId = "attendantId".asTokenizableRaw(), - faceSamples = listOf( - FaceSample(byteArrayOf(), "format", "referenceIdToDelete"), - ), - ), - ) - - val event = ENROLMENT_RECORD_UPDATE - mockProgressEmission(listOf(event)) - - eventDownSyncTask.downSync(this, projectOp, eventScope, project).toList() - - coVerify { - enrolmentRecordRepository.performActions( - withArg { actions -> actions.all { it is Deletion } }, + match> { actions -> + actions.size == 1 && actions.first() is Update + }, any(), ) } diff --git a/infra/logging-persistent/src/test/java/com/simprints/logging/persistent/DatabasePersistentLoggerTest.kt b/infra/logging-persistent/src/test/java/com/simprints/logging/persistent/DatabasePersistentLoggerTest.kt index eacc4400ae..d141c698fe 100644 --- a/infra/logging-persistent/src/test/java/com/simprints/logging/persistent/DatabasePersistentLoggerTest.kt +++ b/infra/logging-persistent/src/test/java/com/simprints/logging/persistent/DatabasePersistentLoggerTest.kt @@ -60,7 +60,7 @@ class DatabasePersistentLoggerTest { coVerify { logEntryDao.save( - coWithArg { + match { it.timestampMs == 0L && it.title == "title" && it.body == "body" }, ) @@ -74,7 +74,7 @@ class DatabasePersistentLoggerTest { coVerify { logEntryDao.save( - coWithArg { + match { it.timestampMs == 1L && it.title == "title" && it.body == "body" }, ) @@ -88,7 +88,7 @@ class DatabasePersistentLoggerTest { coVerify { logEntryDao.save( - coWithArg { + match { it.timestampMs == 0L && it.title == "title" && it.body == "body" }, ) @@ -102,7 +102,7 @@ class DatabasePersistentLoggerTest { coVerify { logEntryDao.save( - coWithArg { + match { it.timestampMs == 1L && it.title == "title" && it.body == "body" }, ) diff --git a/infra/logging/src/test/java/com/simprints/infra/logging/writers/CrashlyticsLogWriterTest.kt b/infra/logging/src/test/java/com/simprints/infra/logging/writers/CrashlyticsLogWriterTest.kt index 07a4f76c00..ac6a422023 100644 --- a/infra/logging/src/test/java/com/simprints/infra/logging/writers/CrashlyticsLogWriterTest.kt +++ b/infra/logging/src/test/java/com/simprints/infra/logging/writers/CrashlyticsLogWriterTest.kt @@ -66,9 +66,7 @@ class CrashlyticsLogWriterTest { verify { crashMock.recordException( - withArg { - it is Exception && it.message.contentEquals("Test Message") - }, + match { it.message?.contains("Test Message") == true } ) } } @@ -84,7 +82,7 @@ class CrashlyticsLogWriterTest { Simber.w("Test Message", custException) verify { - crashMock.log(withArg { it.contains("Test Message") }) + crashMock.log(match { it.contains("Test Message") }) } verify { crashMock.recordException(custException) @@ -102,7 +100,7 @@ class CrashlyticsLogWriterTest { Simber.e("Test Message", custException) verify { - crashMock.log(withArg { it.contains("Test Message") }) + crashMock.log(match { it.contains("Test Message") }) } verify { crashMock.recordException(custException)