From e16f39a67680f8c5e4b4caa71b455b19754cd7ae Mon Sep 17 00:00:00 2001 From: Grzegorz Orczykowski Date: Wed, 16 Oct 2024 14:54:15 +0200 Subject: [PATCH] Fixed tests --- collect_app/.attach_pid25568 | 0 collect_app/.attach_pid28460 | 0 collect_app/.attach_pid29559 | 0 .../odk/collect/android/external/FormUriActivityTest.kt | 4 ++-- .../android/formmanagement/FormsDataServiceTest.kt | 8 ++++---- .../android/formmanagement/ServerFormUseCasesTest.kt | 2 +- .../instancemanagement/InstancesDataServiceTest.kt | 2 +- .../odk/collect/android/projects/ProjectDeleterTest.kt | 4 ++-- .../odk/collect/android/projects/ProjectResetterTest.kt | 2 +- .../java/org/odk/collect/testshared/BooleanChangeLock.kt | 8 ++++++-- 10 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 collect_app/.attach_pid25568 create mode 100644 collect_app/.attach_pid28460 create mode 100644 collect_app/.attach_pid29559 diff --git a/collect_app/.attach_pid25568 b/collect_app/.attach_pid25568 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/collect_app/.attach_pid28460 b/collect_app/.attach_pid28460 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/collect_app/.attach_pid29559 b/collect_app/.attach_pid29559 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/collect_app/src/test/java/org/odk/collect/android/external/FormUriActivityTest.kt b/collect_app/src/test/java/org/odk/collect/android/external/FormUriActivityTest.kt index 53b95c7cb6f..105dc6d417a 100644 --- a/collect_app/src/test/java/org/odk/collect/android/external/FormUriActivityTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/external/FormUriActivityTest.kt @@ -1064,7 +1064,7 @@ class FormUriActivityTest { ).build() ) - changeLock.lock() + changeLock.tryLock() val scenario = launcherRule.launchForResult(getBlankFormIntent(project.uuid, form.dbId)) fakeScheduler.flush() @@ -1093,7 +1093,7 @@ class FormUriActivityTest { .build() ) - changeLock.lock() + changeLock.tryLock() val scenario = launcherRule.launchForResult(getSavedIntent(project.uuid, instance.dbId)) fakeScheduler.flush() diff --git a/collect_app/src/test/java/org/odk/collect/android/formmanagement/FormsDataServiceTest.kt b/collect_app/src/test/java/org/odk/collect/android/formmanagement/FormsDataServiceTest.kt index 55ef60165d9..78da28b159a 100644 --- a/collect_app/src/test/java/org/odk/collect/android/formmanagement/FormsDataServiceTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/formmanagement/FormsDataServiceTest.kt @@ -114,7 +114,7 @@ class FormsDataServiceTest { val isSyncing = formsDataService.isSyncing(project.uuid) val changeLock = changeLockProvider.create(project.uuid).formsLock as BooleanChangeLock - changeLock.lock() + changeLock.tryLock() isSyncing.recordValues { projectValues -> formsDataService.downloadUpdates(project.uuid) @@ -131,7 +131,7 @@ class FormsDataServiceTest { val isSyncing = formsDataService.isSyncing(project.uuid) val changeLock = changeLockProvider.create(project.uuid).formsLock as BooleanChangeLock - changeLock.lock() + changeLock.tryLock() isSyncing.recordValues { projectValues -> formsDataService.matchFormsWithServer(project.uuid) @@ -150,7 +150,7 @@ class FormsDataServiceTest { @Test fun `matchFormsWithServer() returns false when change lock is locked`() { val changeLock = changeLockProvider.create(project.uuid).formsLock as BooleanChangeLock - changeLock.lock() + changeLock.tryLock() assertThat(formsDataService.matchFormsWithServer(project.uuid), equalTo(false)) } @@ -225,7 +225,7 @@ class FormsDataServiceTest { val isSyncing = formsDataService.isSyncing(project.uuid) val changeLock = changeLockProvider.create(project.uuid).formsLock as BooleanChangeLock - changeLock.lock() + changeLock.tryLock() isSyncing.recordValues { projectValues -> formsDataService.update(project.uuid) diff --git a/collect_app/src/test/java/org/odk/collect/android/formmanagement/ServerFormUseCasesTest.kt b/collect_app/src/test/java/org/odk/collect/android/formmanagement/ServerFormUseCasesTest.kt index 0ba9ce813cb..672407c5b1e 100644 --- a/collect_app/src/test/java/org/odk/collect/android/formmanagement/ServerFormUseCasesTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/formmanagement/ServerFormUseCasesTest.kt @@ -34,7 +34,7 @@ class ServerFormUseCasesTest { val changeLock = BooleanChangeLock() val formDownloader = mock() - changeLock.lock() + changeLock.tryLock() val serverForm = ServerFormDetails("", "", "", "", "", false, true, ManifestFile("", emptyList())) diff --git a/collect_app/src/test/java/org/odk/collect/android/instancemanagement/InstancesDataServiceTest.kt b/collect_app/src/test/java/org/odk/collect/android/instancemanagement/InstancesDataServiceTest.kt index 01bc4dd202f..cbe9daf3370 100644 --- a/collect_app/src/test/java/org/odk/collect/android/instancemanagement/InstancesDataServiceTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/instancemanagement/InstancesDataServiceTest.kt @@ -68,7 +68,7 @@ class InstancesDataServiceTest { @Test fun `instances should not be deleted if the instances database is locked`() { - (projectDependencyModule.instancesLock as BooleanChangeLock).lock() + (projectDependencyModule.instancesLock as BooleanChangeLock).tryLock() val result = instancesDataService.deleteInstances("projectId", longArrayOf(1)) assertThat(result, equalTo(false)) } diff --git a/collect_app/src/test/java/org/odk/collect/android/projects/ProjectDeleterTest.kt b/collect_app/src/test/java/org/odk/collect/android/projects/ProjectDeleterTest.kt index 4100a188cf7..7183310f7b4 100644 --- a/collect_app/src/test/java/org/odk/collect/android/projects/ProjectDeleterTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/projects/ProjectDeleterTest.kt @@ -153,7 +153,7 @@ class ProjectDeleterTest { @Test fun `If there are running background jobs that use blank forms the project should not be deleted`() { val formChangeLock = BooleanChangeLock().apply { - lock() + tryLock() } whenever(changeLockProvider.getFormLock(any())).thenReturn(formChangeLock) @@ -166,7 +166,7 @@ class ProjectDeleterTest { @Test fun `If there are running background jobs that use saved forms the project should not be deleted`() { val changeLock = BooleanChangeLock().apply { - lock() + tryLock() } whenever(changeLockProvider.getInstanceLock(any())).thenReturn(changeLock) diff --git a/collect_app/src/test/java/org/odk/collect/android/projects/ProjectResetterTest.kt b/collect_app/src/test/java/org/odk/collect/android/projects/ProjectResetterTest.kt index 2fcc0c497ae..60da6571348 100644 --- a/collect_app/src/test/java/org/odk/collect/android/projects/ProjectResetterTest.kt +++ b/collect_app/src/test/java/org/odk/collect/android/projects/ProjectResetterTest.kt @@ -202,7 +202,7 @@ class ProjectResetterTest { saveTestInstanceFiles(currentProjectId) setupTestInstancesDatabase(currentProjectId) - (changeLockProvider.create(currentProjectId).instancesLock as BooleanChangeLock).lock() + (changeLockProvider.create(currentProjectId).instancesLock as BooleanChangeLock).tryLock() val failedResetActions = projectResetter.reset(listOf(ProjectResetter.ResetAction.RESET_INSTANCES)) assertEquals(1, failedResetActions.size) diff --git a/test-shared/src/main/java/org/odk/collect/testshared/BooleanChangeLock.kt b/test-shared/src/main/java/org/odk/collect/testshared/BooleanChangeLock.kt index 295ddc59ef1..3dfce709c06 100644 --- a/test-shared/src/main/java/org/odk/collect/testshared/BooleanChangeLock.kt +++ b/test-shared/src/main/java/org/odk/collect/testshared/BooleanChangeLock.kt @@ -11,8 +11,12 @@ class BooleanChangeLock : ChangeLock { } override fun tryLock(): Boolean { - isLocked = true - return true + if (!isLocked) { + isLocked = true + return true + } else { + return false + } } override fun unlock() {