CountingTaskExecutorRule


class CountingTaskExecutorRule : TestWatcher


A JUnit Test Rule that swaps the background executor used by the Architecture Components with a different one which counts the tasks as they are start and finish.

You can use this rule for your host side tests that use Architecture Components.

Summary

Public constructors

Public functions

Unit
drainTasks(time: Int, timeUnit: TimeUnit)

Waits until all active tasks are finished.

Boolean

Returns false if there are tasks waiting to be executed, true otherwise.

Protected functions

Unit
finished(description: Description!)
Unit

Called when the number of awaiting tasks reaches to 0.

Unit
starting(description: Description!)

Inherited functions

From org.junit.rules.TestWatcher
Statement!
apply(base: Statement!, description: Description!)
Unit
failed(e: Throwable!, description: Description!)
Unit
Unit
succeeded(description: Description!)

Public constructors

CountingTaskExecutorRule

Added in 2.0.0
CountingTaskExecutorRule()

Public functions

drainTasks

Added in 2.0.0
fun drainTasks(time: Int, timeUnit: TimeUnit): Unit

Waits until all active tasks are finished.

Parameters
time: Int

The duration to wait

timeUnit: TimeUnit

The time unit for the time parameter

Throws
java.lang.InterruptedException

If thread is interrupted while waiting

java.util.concurrent.TimeoutException

If tasks cannot be drained at the given time

isIdle

Added in 2.0.0
fun isIdle(): Boolean

Returns false if there are tasks waiting to be executed, true otherwise.

Returns
Boolean

False if there are tasks waiting to be executed, true otherwise.

See also
onIdle

Protected functions

finished

protected fun finished(description: Description!): Unit

onIdle

Added in 2.0.0
protected fun onIdle(): Unit

Called when the number of awaiting tasks reaches to 0.

See also
isIdle

starting

protected fun starting(description: Description!): Unit