mirror of https://github.com/tasks/tasks
Fix tests
parent
c2222657ec
commit
120eb4dd30
@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2012 Todoroo Inc
|
|
||||||
*
|
|
||||||
* See the file "LICENSE" for the full license governing this code.
|
|
||||||
*/
|
|
||||||
package com.todoroo.astrid.gtasks
|
|
||||||
|
|
||||||
import com.todoroo.astrid.dao.TaskDao
|
|
||||||
import com.todoroo.astrid.data.Task
|
|
||||||
import dagger.hilt.android.testing.HiltAndroidTest
|
|
||||||
import dagger.hilt.android.testing.UninstallModules
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.junit.Assert.assertNotNull
|
|
||||||
import org.junit.Assert.assertNull
|
|
||||||
import org.junit.Test
|
|
||||||
import org.tasks.data.GoogleTaskDao
|
|
||||||
import org.tasks.injection.InjectingTestCase
|
|
||||||
import org.tasks.injection.ProductionModule
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@UninstallModules(ProductionModule::class)
|
|
||||||
@HiltAndroidTest
|
|
||||||
class GtasksMetadataServiceTest : InjectingTestCase() {
|
|
||||||
@Inject lateinit var taskDao: TaskDao
|
|
||||||
@Inject lateinit var googleTaskDao: GoogleTaskDao
|
|
||||||
|
|
||||||
private var task: Task? = null
|
|
||||||
private var metadata: GoogleTask? = null
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testMetadataFound() = runBlocking {
|
|
||||||
givenTask(taskWithMetadata(null))
|
|
||||||
whenSearchForMetadata()
|
|
||||||
thenExpectMetadataFound()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun testMetadataDoesntExist() = runBlocking {
|
|
||||||
givenTask(taskWithoutMetadata())
|
|
||||||
whenSearchForMetadata()
|
|
||||||
thenExpectNoMetadataFound()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun thenExpectNoMetadataFound() {
|
|
||||||
assertNull(metadata)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun thenExpectMetadataFound() {
|
|
||||||
assertNotNull(metadata)
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- helpers
|
|
||||||
private suspend fun whenSearchForMetadata() {
|
|
||||||
metadata = googleTaskDao.getByTaskId(task!!.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun taskWithMetadata(id: String?): Task {
|
|
||||||
val task = Task()
|
|
||||||
task.title = "cats"
|
|
||||||
taskDao.createNew(task)
|
|
||||||
val metadata = GoogleTask(task.id, "")
|
|
||||||
if (id != null) {
|
|
||||||
metadata.remoteId = id
|
|
||||||
}
|
|
||||||
metadata.task = task.id
|
|
||||||
googleTaskDao.insert(metadata)
|
|
||||||
return task
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun givenTask(taskToTest: Task) {
|
|
||||||
task = taskToTest
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun taskWithoutMetadata(): Task {
|
|
||||||
val task = Task()
|
|
||||||
task.title = "dogs"
|
|
||||||
taskDao.createNew(task)
|
|
||||||
return task
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package org.tasks.makers
|
||||||
|
|
||||||
|
import com.natpryce.makeiteasy.Instantiator
|
||||||
|
import com.natpryce.makeiteasy.Property
|
||||||
|
import com.natpryce.makeiteasy.Property.newProperty
|
||||||
|
import com.natpryce.makeiteasy.PropertyValue
|
||||||
|
import org.tasks.data.CaldavAccount
|
||||||
|
import org.tasks.data.CaldavAccount.Companion.TYPE_CALDAV
|
||||||
|
import org.tasks.makers.Maker.make
|
||||||
|
|
||||||
|
object CaldavAccountMaker {
|
||||||
|
val ID: Property<CaldavAccount, Long> = newProperty()
|
||||||
|
val NAME: Property<CaldavAccount, String> = newProperty()
|
||||||
|
val UUID: Property<CaldavAccount, String> = newProperty()
|
||||||
|
val ACCOUNT_TYPE: Property<CaldavAccount, Int> = newProperty()
|
||||||
|
|
||||||
|
private val instantiator = Instantiator { lookup ->
|
||||||
|
CaldavAccount().apply {
|
||||||
|
id = lookup.valueOf(ID, 0L)
|
||||||
|
name = lookup.valueOf(NAME, null as String?)
|
||||||
|
uuid = lookup.valueOf(UUID, "account")
|
||||||
|
accountType = lookup.valueOf(ACCOUNT_TYPE, TYPE_CALDAV)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun newCaldavAccount(vararg properties: PropertyValue<in CaldavAccount?, *>): CaldavAccount {
|
||||||
|
return make(instantiator, *properties)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,24 +0,0 @@
|
|||||||
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.uuid = lookup.valueOf(REMOTE_ID, "1234")
|
|
||||||
list.account = lookup.valueOf(ACCOUNT, null as String?)
|
|
||||||
list.setColor(0)
|
|
||||||
list
|
|
||||||
}
|
|
||||||
|
|
||||||
fun newGoogleTaskList(vararg properties: PropertyValue<in GoogleTaskList?, *>): GoogleTaskList {
|
|
||||||
return Maker.make(instantiator, *properties)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
package org.tasks.makers
|
|
||||||
|
|
||||||
import com.natpryce.makeiteasy.Instantiator
|
|
||||||
import com.natpryce.makeiteasy.Property
|
|
||||||
import com.natpryce.makeiteasy.Property.newProperty
|
|
||||||
import com.natpryce.makeiteasy.PropertyValue
|
|
||||||
import com.todoroo.astrid.helper.UUIDHelper
|
|
||||||
import org.tasks.makers.Maker.make
|
|
||||||
|
|
||||||
object GoogleTaskMaker {
|
|
||||||
val LIST: Property<GoogleTask, String> = newProperty()
|
|
||||||
val ORDER: Property<GoogleTask, Long> = newProperty()
|
|
||||||
val REMOTE_ID: Property<GoogleTask, String> = newProperty()
|
|
||||||
val TASK: Property<GoogleTask, Long> = newProperty()
|
|
||||||
val PARENT: Property<GoogleTask, Long> = newProperty()
|
|
||||||
val REMOTE_PARENT: Property<GoogleTask, String?> = newProperty()
|
|
||||||
|
|
||||||
private val instantiator = Instantiator<GoogleTask> {
|
|
||||||
val task = GoogleTask()
|
|
||||||
task.calendar = it.valueOf(LIST, "1")
|
|
||||||
task.order = it.valueOf(ORDER, 0)
|
|
||||||
task.remoteId = it.valueOf(REMOTE_ID, UUIDHelper.newUUID())
|
|
||||||
task.task = it.valueOf(TASK, 1)
|
|
||||||
task.parent = it.valueOf(PARENT, 0L)
|
|
||||||
task.remoteParent = it.valueOf(REMOTE_PARENT, null as String?)
|
|
||||||
task
|
|
||||||
}
|
|
||||||
|
|
||||||
fun newGoogleTask(vararg properties: PropertyValue<in GoogleTask?, *>): GoogleTask {
|
|
||||||
return make(instantiator, *properties)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
package org.tasks.makers
|
|
||||||
|
|
||||||
import com.natpryce.makeiteasy.Instantiator
|
|
||||||
import com.natpryce.makeiteasy.Property
|
|
||||||
import com.natpryce.makeiteasy.Property.newProperty
|
|
||||||
import com.natpryce.makeiteasy.PropertyLookup
|
|
||||||
import com.natpryce.makeiteasy.PropertyValue
|
|
||||||
import com.todoroo.astrid.api.FilterListItem.NO_ORDER
|
|
||||||
import org.tasks.data.GoogleTaskList
|
|
||||||
import org.tasks.makers.Maker.make
|
|
||||||
|
|
||||||
object GtaskListMaker {
|
|
||||||
val ID: Property<GoogleTaskList, Long> = newProperty()
|
|
||||||
val ACCOUNT: Property<GoogleTaskList, String> = newProperty()
|
|
||||||
val REMOTE_ID: Property<GoogleTaskList, String> = newProperty()
|
|
||||||
val LAST_SYNC: Property<GoogleTaskList, Long> = newProperty()
|
|
||||||
val NAME: Property<GoogleTaskList, String> = newProperty()
|
|
||||||
private val ORDER: Property<GoogleTaskList, Int> = newProperty()
|
|
||||||
private val COLOR: Property<GoogleTaskList, Int> = newProperty()
|
|
||||||
|
|
||||||
private val instantiator = Instantiator { lookup: PropertyLookup<GoogleTaskList> ->
|
|
||||||
val list = GoogleTaskList()
|
|
||||||
list.id = lookup.valueOf(ID, 0L)
|
|
||||||
list.account = lookup.valueOf(ACCOUNT, "account")
|
|
||||||
list.uuid = lookup.valueOf(REMOTE_ID, "1")
|
|
||||||
list.name = lookup.valueOf(NAME, "Default")
|
|
||||||
list.order = lookup.valueOf(ORDER, NO_ORDER)
|
|
||||||
list.lastSync = lookup.valueOf(LAST_SYNC, 0L)
|
|
||||||
list.setColor(lookup.valueOf(COLOR, 0))
|
|
||||||
list
|
|
||||||
}
|
|
||||||
|
|
||||||
fun newGtaskList(vararg properties: PropertyValue<in GoogleTaskList?, *>): GoogleTaskList {
|
|
||||||
return make(instantiator, *properties)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue