From 644eda1eefc7a45e45c8c94845ecfa82e5695353 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Tue, 29 Nov 2022 22:57:04 -0600 Subject: [PATCH] Fix tests --- .../tasks/caldav/CaldavSynchronizerTest.kt | 22 +++---- .../tasks/caldav/SharingMailboxDotOrgTest.kt | 24 ++++---- .../org/tasks/caldav/SharingOwncloudTest.kt | 48 +++++++-------- .../org/tasks/caldav/SharingSabredavTest.kt | 61 ++++++++++--------- .../opentasks/OpenTasksSynchronizerTest.kt | 10 +-- .../org/tasks/opentasks/TestOpenTaskDao.kt | 15 ++--- .../org/tasks/makers/CaldavCalendarMaker.kt | 10 +-- 7 files changed, 97 insertions(+), 93 deletions(-) diff --git a/app/src/androidTest/java/org/tasks/caldav/CaldavSynchronizerTest.kt b/app/src/androidTest/java/org/tasks/caldav/CaldavSynchronizerTest.kt index 062283824..b567ee1e4 100644 --- a/app/src/androidTest/java/org/tasks/caldav/CaldavSynchronizerTest.kt +++ b/app/src/androidTest/java/org/tasks/caldav/CaldavSynchronizerTest.kt @@ -45,11 +45,11 @@ class CaldavSynchronizerTest : CaldavTest() { @Test fun dontFetchCalendarIfCtagMatches() = runBlocking { - caldavDao.insert(CaldavCalendar().apply { - account = this@CaldavSynchronizerTest.account.uuid - ctag = "http://sabre.io/ns/sync/1" - url = "${this@CaldavSynchronizerTest.account.url}test-shared/" - }) + caldavDao.insert(CaldavCalendar( + account = this@CaldavSynchronizerTest.account.uuid, + ctag = "http://sabre.io/ns/sync/1", + url = "${this@CaldavSynchronizerTest.account.url}test-shared/", + )) enqueue(OC_SHARE_PROPFIND) sync() @@ -57,12 +57,12 @@ class CaldavSynchronizerTest : CaldavTest() { @Test fun dontFetchTaskIfEtagMatches() = runBlocking { - val calendar = CaldavCalendar().apply { - account = this@CaldavSynchronizerTest.account.uuid - uuid = UUIDHelper.newUUID() - url = "${this@CaldavSynchronizerTest.account.url}test-shared/" - caldavDao.insert(this) - } + val calendar = CaldavCalendar( + account = this@CaldavSynchronizerTest.account.uuid, + uuid = UUIDHelper.newUUID(), + url = "${this@CaldavSynchronizerTest.account.url}test-shared/", + ) + caldavDao.insert(calendar) caldavDao.insert(newCaldavTask( with(TASK, taskDao.insert(newTask())), with(OBJECT, "3164728546640386952.ics"), diff --git a/app/src/androidTest/java/org/tasks/caldav/SharingMailboxDotOrgTest.kt b/app/src/androidTest/java/org/tasks/caldav/SharingMailboxDotOrgTest.kt index 1bda05075..8b535b470 100644 --- a/app/src/androidTest/java/org/tasks/caldav/SharingMailboxDotOrgTest.kt +++ b/app/src/androidTest/java/org/tasks/caldav/SharingMailboxDotOrgTest.kt @@ -29,12 +29,12 @@ class SharingMailboxDotOrgTest : CaldavTest() { url = server.url("/caldav/").toString() id = caldavDao.insert(this) } - val calendar = CaldavCalendar().apply { - account = this@SharingMailboxDotOrgTest.account.uuid - ctag = "1614876450015" - url = "${this@SharingMailboxDotOrgTest.account.url}MzM/" - caldavDao.insert(this) - } + val calendar = CaldavCalendar( + account = this@SharingMailboxDotOrgTest.account.uuid, + ctag = "1614876450015", + url = "${this@SharingMailboxDotOrgTest.account.url}MzM/", + ) + caldavDao.insert(calendar) enqueue(SHARE_OWNER) sync() @@ -52,12 +52,12 @@ class SharingMailboxDotOrgTest : CaldavTest() { url = server.url("/caldav/").toString() id = caldavDao.insert(this) } - val calendar = CaldavCalendar().apply { - account = this@SharingMailboxDotOrgTest.account.uuid - ctag = "1614876450015" - url = "${this@SharingMailboxDotOrgTest.account.url}MzM/" - caldavDao.insert(this) - } + val calendar = CaldavCalendar( + account = this@SharingMailboxDotOrgTest.account.uuid, + ctag = "1614876450015", + url = "${this@SharingMailboxDotOrgTest.account.url}MzM/", + ) + caldavDao.insert(calendar) enqueue(SHARE_OWNER) sync() diff --git a/app/src/androidTest/java/org/tasks/caldav/SharingOwncloudTest.kt b/app/src/androidTest/java/org/tasks/caldav/SharingOwncloudTest.kt index ea3f12c45..748ebb887 100644 --- a/app/src/androidTest/java/org/tasks/caldav/SharingOwncloudTest.kt +++ b/app/src/androidTest/java/org/tasks/caldav/SharingOwncloudTest.kt @@ -33,12 +33,12 @@ class SharingOwncloudTest : CaldavTest() { @Test fun calendarOwner() = runBlocking { setupAccount("user1") - val calendar = CaldavCalendar().apply { - account = this@SharingOwncloudTest.account.uuid - ctag = "http://sabre.io/ns/sync/1" - url = "${this@SharingOwncloudTest.account.url}test-shared/" - caldavDao.insert(this) - } + val calendar = CaldavCalendar( + account = this@SharingOwncloudTest.account.uuid, + ctag = "http://sabre.io/ns/sync/1", + url = "${this@SharingOwncloudTest.account.url}test-shared/", + ) + caldavDao.insert(calendar) enqueue(OC_OWNER) sync() @@ -49,12 +49,12 @@ class SharingOwncloudTest : CaldavTest() { @Test fun readOnly() = runBlocking { setupAccount("user2") - val calendar = CaldavCalendar().apply { - account = this@SharingOwncloudTest.account.uuid - ctag = "http://sabre.io/ns/sync/2" - url = "${this@SharingOwncloudTest.account.url}test-shared_shared_by_user1/" - caldavDao.insert(this) - } + val calendar = CaldavCalendar( + account = this@SharingOwncloudTest.account.uuid, + ctag = "http://sabre.io/ns/sync/2", + url = "${this@SharingOwncloudTest.account.url}test-shared_shared_by_user1/", + ) + caldavDao.insert(calendar) enqueue(OC_READ_ONLY) sync() @@ -65,12 +65,12 @@ class SharingOwncloudTest : CaldavTest() { @Test fun principalForSharee() = runBlocking { setupAccount("user1") - val calendar = CaldavCalendar().apply { - account = this@SharingOwncloudTest.account.uuid - ctag = "http://sabre.io/ns/sync/1" - url = "${this@SharingOwncloudTest.account.url}test-shared/" - caldavDao.insert(this) - } + val calendar = CaldavCalendar( + account = this@SharingOwncloudTest.account.uuid, + ctag = "http://sabre.io/ns/sync/1", + url = "${this@SharingOwncloudTest.account.url}test-shared/", + ) + caldavDao.insert(calendar) enqueue(OC_OWNER) sync() @@ -89,12 +89,12 @@ class SharingOwncloudTest : CaldavTest() { @Test fun principalForOwner() = runBlocking { setupAccount("user2") - val calendar = CaldavCalendar().apply { - account = this@SharingOwncloudTest.account.uuid - ctag = "http://sabre.io/ns/sync/2" - url = "${this@SharingOwncloudTest.account.url}test-shared_shared_by_user1/" - caldavDao.insert(this) - } + val calendar = CaldavCalendar( + account = this@SharingOwncloudTest.account.uuid, + ctag = "http://sabre.io/ns/sync/2", + url = "${this@SharingOwncloudTest.account.url}test-shared_shared_by_user1/", + ) + caldavDao.insert(calendar) enqueue(OC_READ_ONLY) sync() diff --git a/app/src/androidTest/java/org/tasks/caldav/SharingSabredavTest.kt b/app/src/androidTest/java/org/tasks/caldav/SharingSabredavTest.kt index 08aded864..061a120e4 100644 --- a/app/src/androidTest/java/org/tasks/caldav/SharingSabredavTest.kt +++ b/app/src/androidTest/java/org/tasks/caldav/SharingSabredavTest.kt @@ -35,12 +35,12 @@ class SharingSabredavTest : CaldavTest() { @Test fun calendarOwner() = runBlocking { setupAccount("user1") - val calendar = CaldavCalendar().apply { - account = this@SharingSabredavTest.account.uuid - ctag = "http://sabre.io/ns/sync/1" - url = "${this@SharingSabredavTest.account.url}940468858232147861/" - caldavDao.insert(this) - } + val calendar = CaldavCalendar( + account = this@SharingSabredavTest.account.uuid, + ctag = "http://sabre.io/ns/sync/1", + url = "${this@SharingSabredavTest.account.url}940468858232147861/", + ) + caldavDao.insert(calendar) enqueue(SD_OWNER) sync() @@ -54,12 +54,12 @@ class SharingSabredavTest : CaldavTest() { @Test fun calendarSharee() = runBlocking { setupAccount("user2") - val calendar = CaldavCalendar().apply { - account = this@SharingSabredavTest.account.uuid - ctag = "http://sabre.io/ns/sync/1" - url = "${this@SharingSabredavTest.account.url}c3853d69-cb7a-476c-a23b-30ffd70f110b/" - caldavDao.insert(this) - } + val calendar = CaldavCalendar( + account = this@SharingSabredavTest.account.uuid, + ctag = "http://sabre.io/ns/sync/1", + url = "${this@SharingSabredavTest.account.url}c3853d69-cb7a-476c-a23b-30ffd70f110b/", + ) + caldavDao.insert(calendar) enqueue(SD_SHAREE) sync() @@ -73,12 +73,13 @@ class SharingSabredavTest : CaldavTest() { @Test fun excludeCurrentUserPrincipalFromSharees() = runBlocking { setupAccount("user1") - CaldavCalendar().apply { - account = this@SharingSabredavTest.account.uuid - ctag = "http://sabre.io/ns/sync/1" - url = "${this@SharingSabredavTest.account.url}940468858232147861/" - caldavDao.insert(this) - } + caldavDao.insert( + CaldavCalendar( + account = account.uuid, + ctag = "http://sabre.io/ns/sync/1", + url = "${account.url}940468858232147861/", + ) + ) enqueue(SD_OWNER) sync() @@ -89,12 +90,12 @@ class SharingSabredavTest : CaldavTest() { @Test fun principalForSharee() = runBlocking { setupAccount("user1") - val calendar = CaldavCalendar().apply { - account = this@SharingSabredavTest.account.uuid - ctag = "http://sabre.io/ns/sync/1" - url = "${this@SharingSabredavTest.account.url}940468858232147861/" - caldavDao.insert(this) - } + val calendar = CaldavCalendar( + account = this@SharingSabredavTest.account.uuid, + ctag = "http://sabre.io/ns/sync/1", + url = "${this@SharingSabredavTest.account.url}940468858232147861/", + ) + caldavDao.insert(calendar) enqueue(SD_OWNER) sync() @@ -111,12 +112,12 @@ class SharingSabredavTest : CaldavTest() { @Test fun principalForOwner() = runBlocking { setupAccount("user2") - val calendar = CaldavCalendar().apply { - account = this@SharingSabredavTest.account.uuid - ctag = "http://sabre.io/ns/sync/1" - url = "${this@SharingSabredavTest.account.url}c3853d69-cb7a-476c-a23b-30ffd70f110b/" - caldavDao.insert(this) - } + val calendar = CaldavCalendar( + account = this@SharingSabredavTest.account.uuid, + ctag = "http://sabre.io/ns/sync/1", + url = "${this@SharingSabredavTest.account.url}c3853d69-cb7a-476c-a23b-30ffd70f110b/", + ) + caldavDao.insert(calendar) enqueue(SD_SHAREE) sync() diff --git a/app/src/androidTest/java/org/tasks/opentasks/OpenTasksSynchronizerTest.kt b/app/src/androidTest/java/org/tasks/opentasks/OpenTasksSynchronizerTest.kt index 0e9ec6179..c558a1ccd 100644 --- a/app/src/androidTest/java/org/tasks/opentasks/OpenTasksSynchronizerTest.kt +++ b/app/src/androidTest/java/org/tasks/opentasks/OpenTasksSynchronizerTest.kt @@ -64,10 +64,12 @@ class OpenTasksSynchronizerTest : OpenTasksTest() { @Test fun removeMissingLists() = runBlocking { val (_, list) = openTaskDao.insertList(url = "url1") - caldavDao.insert(CaldavCalendar().apply { - account = list.account - url = "url2" - }) + caldavDao.insert( + CaldavCalendar( + account = list.account, + url = "url2", + ) + ) synchronizer.sync() diff --git a/app/src/androidTest/java/org/tasks/opentasks/TestOpenTaskDao.kt b/app/src/androidTest/java/org/tasks/opentasks/TestOpenTaskDao.kt index 0ddccef71..2d03b07f7 100644 --- a/app/src/androidTest/java/org/tasks/opentasks/TestOpenTaskDao.kt +++ b/app/src/androidTest/java/org/tasks/opentasks/TestOpenTaskDao.kt @@ -35,13 +35,14 @@ class TestOpenTaskDao @Inject constructor( .withValue(TaskContract.TaskListColumns.LIST_NAME, name) .withValue(TaskContract.TaskLists.SYNC_ENABLED, "1") ) - return Pair(result.uri!!.lastPathSegment!!.toLong(), CaldavCalendar().apply { - uuid = UUIDHelper.newUUID() - this.name = name - this.account = "$type:$account" - this.url = url - caldavDao.insert(this) - }) + val calendar = CaldavCalendar( + uuid = UUIDHelper.newUUID(), + name = name, + account = "$type:$account", + url = url, + ) + caldavDao.insert(calendar) + return Pair(result.uri!!.lastPathSegment!!.toLong(), calendar) } fun insertTask(listId: Long, vtodo: String) { diff --git a/app/src/test/java/org/tasks/makers/CaldavCalendarMaker.kt b/app/src/test/java/org/tasks/makers/CaldavCalendarMaker.kt index bd3d70bc3..65a9a272b 100644 --- a/app/src/test/java/org/tasks/makers/CaldavCalendarMaker.kt +++ b/app/src/test/java/org/tasks/makers/CaldavCalendarMaker.kt @@ -11,11 +11,11 @@ object CaldavCalendarMaker { val ACCOUNT: Property = newProperty() val UUID: Property = newProperty() - private val instantiator = Instantiator { lookup -> - val calendar = CaldavCalendar() - calendar.account = lookup.valueOf(ACCOUNT, "account") - calendar.uuid = lookup.valueOf(UUID, "uuid") - calendar + private val instantiator = Instantiator { lookup -> + CaldavCalendar( + account = lookup.valueOf(ACCOUNT, "account"), + uuid = lookup.valueOf(UUID, "uuid"), + ) } fun newCaldavCalendar(vararg properties: PropertyValue): CaldavCalendar {