From 27f45e64a45aaa317250b489cc5cef9bbcd292ef Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Tue, 31 Mar 2020 10:57:19 -0500 Subject: [PATCH] Add findExistingList tests --- .../org/tasks/data/GoogleTaskListDaoTest.kt | 30 ++++++++++++++++++- .../org/tasks/makers/GoogleTaskListMaker.kt | 24 +++++++++++++++ .../org/tasks/data/GoogleTaskListDao.java | 4 +-- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 app/src/androidTest/java/org/tasks/makers/GoogleTaskListMaker.kt diff --git a/app/src/androidTest/java/org/tasks/data/GoogleTaskListDaoTest.kt b/app/src/androidTest/java/org/tasks/data/GoogleTaskListDaoTest.kt index 9da581752..1aa78a84c 100644 --- a/app/src/androidTest/java/org/tasks/data/GoogleTaskListDaoTest.kt +++ b/app/src/androidTest/java/org/tasks/data/GoogleTaskListDaoTest.kt @@ -1,12 +1,16 @@ package org.tasks.data import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.natpryce.makeiteasy.MakeItEasy.with import com.todoroo.andlib.utility.DateUtilities.now -import org.junit.Assert.assertTrue +import org.junit.Assert.* import org.junit.Test import org.junit.runner.RunWith import org.tasks.injection.InjectingTestCase import org.tasks.injection.TestComponent +import org.tasks.makers.GoogleTaskListMaker.ACCOUNT +import org.tasks.makers.GoogleTaskListMaker.REMOTE_ID +import org.tasks.makers.GoogleTaskListMaker.newGoogleTaskList import javax.inject.Inject @RunWith(AndroidJUnit4::class) @@ -23,5 +27,29 @@ class GoogleTaskListDaoTest : InjectingTestCase() { assertTrue(googleTaskListDao.getGoogleTaskFilters(account.account, now()).isEmpty()) } + @Test + fun findListWithNullAccount() { + val list = newGoogleTaskList(with(REMOTE_ID, "1234"), with(ACCOUNT, null as String?)) + list.id = googleTaskListDao.insert(list) + + assertEquals(list, googleTaskListDao.findExistingList("1234")) + } + + @Test + fun findListWithEmptyAccount() { + val list = newGoogleTaskList(with(REMOTE_ID, "1234"), with(ACCOUNT, "")) + list.id = googleTaskListDao.insert(list) + + assertEquals(list, googleTaskListDao.findExistingList("1234")) + } + + @Test + fun ignoreListWithAccount() { + val list = newGoogleTaskList(with(REMOTE_ID, "1234"), with(ACCOUNT, "user@gmail.com")) + googleTaskListDao.insert(list) + + assertNull(googleTaskListDao.findExistingList("1234")) + } + override fun inject(component: TestComponent) = component.inject(this) } \ No newline at end of file diff --git a/app/src/androidTest/java/org/tasks/makers/GoogleTaskListMaker.kt b/app/src/androidTest/java/org/tasks/makers/GoogleTaskListMaker.kt new file mode 100644 index 000000000..a6771432d --- /dev/null +++ b/app/src/androidTest/java/org/tasks/makers/GoogleTaskListMaker.kt @@ -0,0 +1,24 @@ +package org.tasks.makers + +import com.natpryce.makeiteasy.Instantiator +import com.natpryce.makeiteasy.Property +import com.natpryce.makeiteasy.PropertyLookup +import com.natpryce.makeiteasy.PropertyValue +import org.tasks.data.GoogleTaskList + +object GoogleTaskListMaker { + val REMOTE_ID: Property = Property.newProperty() + val ACCOUNT: Property = Property.newProperty() + + private val instantiator = Instantiator { lookup: PropertyLookup -> + val list = GoogleTaskList() + list.remoteId = lookup.valueOf(REMOTE_ID, "1234") + list.account = lookup.valueOf(ACCOUNT, null as String?) + list.color = 0 + list + } + + fun newGoogleTaskList(vararg properties: PropertyValue): GoogleTaskList { + return Maker.make(instantiator, *properties) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/tasks/data/GoogleTaskListDao.java b/app/src/main/java/org/tasks/data/GoogleTaskListDao.java index bdce2d16e..908627e6a 100644 --- a/app/src/main/java/org/tasks/data/GoogleTaskListDao.java +++ b/app/src/main/java/org/tasks/data/GoogleTaskListDao.java @@ -38,7 +38,7 @@ public abstract class GoogleTaskListDao { public abstract LiveData> subscribeToLists(); @Query( - "SELECT * FROM google_task_lists WHERE gtl_remote_id = :remoteId AND IFNULL(gtl_account, '') = '' LIMIT 1") + "SELECT * FROM google_task_lists WHERE gtl_remote_id = :remoteId AND IFNULL(gtl_account, '') = ''") public abstract GoogleTaskList findExistingList(String remoteId); @Query("SELECT * FROM google_task_lists") @@ -51,7 +51,7 @@ public abstract class GoogleTaskListDao { public abstract long insertOrReplace(GoogleTaskList googleTaskList); @Insert - public abstract void insert(GoogleTaskList googleTaskList); + public abstract long insert(GoogleTaskList googleTaskList); @Insert public abstract void insert(GoogleTaskAccount googleTaskAccount);