Add findExistingList tests

pull/996/head
Alex Baker 5 years ago
parent 972c1191fe
commit 27f45e64a4

@ -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)
}

@ -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<GoogleTaskList, String> = Property.newProperty()
val ACCOUNT: Property<GoogleTaskList, String?> = Property.newProperty()
private val instantiator = Instantiator { lookup: PropertyLookup<GoogleTaskList> ->
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<in GoogleTaskList?, *>): GoogleTaskList {
return Maker.make(instantiator, *properties)
}
}

@ -38,7 +38,7 @@ public abstract class GoogleTaskListDao {
public abstract LiveData<List<GoogleTaskList>> 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);

Loading…
Cancel
Save