Add recursive loop tests

pull/1061/head
Alex Baker 4 years ago
parent e9ab544b34
commit 97cb202f22

@ -0,0 +1,88 @@
package com.todoroo.astrid.adapter
import com.natpryce.makeiteasy.MakeItEasy.with
import com.natpryce.makeiteasy.PropertyValue
import com.todoroo.astrid.core.BuiltInFilterExposer
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.assertEquals
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.tasks.data.TaskListQuery.getQuery
import org.tasks.date.DateTimeUtils.newDateTime
import org.tasks.injection.InjectingTestCase
import org.tasks.injection.ProductionModule
import org.tasks.makers.TaskMaker.DUE_DATE
import org.tasks.makers.TaskMaker.PARENT
import org.tasks.makers.TaskMaker.newTask
import org.tasks.preferences.Preferences
import javax.inject.Inject
@UninstallModules(ProductionModule::class)
@HiltAndroidTest
class RecursiveLoopTest : InjectingTestCase() {
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var preferences: Preferences
@Before
override fun setUp() {
super.setUp()
preferences.clear()
}
@Test
@Ignore("infinite loop")
fun handleSelfLoop() = runBlocking {
val id = addTask(with(DUE_DATE, newDateTime()))
taskDao.setParent(id, listOf(id))
val tasks = getTasks()
assertEquals(1, tasks.size)
assertEquals(id, tasks[0].id)
}
@Test
@Ignore("infinite loop")
fun handleSingleLevelLoop() = runBlocking {
val parent = addTask(with(DUE_DATE, newDateTime()))
val child = addTask(with(PARENT, parent))
taskDao.setParent(child, listOf(parent))
val tasks = getTasks()
assertEquals(2, tasks.size)
assertEquals(parent, tasks[0].id)
assertEquals(child, tasks[1].id)
}
@Test
@Ignore("infinite loop")
fun handleMultiLevelLoop() = runBlocking {
val parent = addTask(with(DUE_DATE, newDateTime()))
val child = addTask(with(PARENT, parent))
val grandchild = addTask(with(PARENT, child))
taskDao.setParent(grandchild, listOf(parent))
val tasks = getTasks()
assertEquals(3, tasks.size)
assertEquals(parent, tasks[0].id)
assertEquals(child, tasks[1].id)
assertEquals(grandchild, tasks[2].id)
}
private suspend fun getTasks() = taskDao.fetchTasks {
getQuery(preferences, BuiltInFilterExposer.getTodayFilter(context.resources), it)
}
private suspend fun addTask(vararg properties: PropertyValue<in Task?, *>): Long {
val task = newTask(*properties)
taskDao.createNew(task)
return task.id
}
}

@ -1,11 +1,12 @@
package org.tasks.injection
import android.content.Context
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import dagger.hilt.android.testing.HiltAndroidRule
import org.junit.Before
import org.junit.Rule
abstract class InjectingTestCase {
@get:Rule
var hiltRule = HiltAndroidRule(this)
@ -13,4 +14,7 @@ abstract class InjectingTestCase {
open fun setUp() {
hiltRule.inject()
}
protected val context: Context
get() = getApplicationContext()
}

@ -27,7 +27,6 @@ import org.tasks.ui.TaskEditViewModel
import javax.inject.Inject
open class BaseTaskEditViewModelTest : InjectingTestCase() {
@ApplicationContext @Inject lateinit var context: Context
@Inject lateinit var db: Database
@Inject lateinit var taskDao: TaskDao
@Inject lateinit var taskDeleter: TaskDeleter

Loading…
Cancel
Save