CountingTaskExecutorRule

public class CountingTaskExecutorRule extends 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 methods

void
drainTasks(int time, @NonNull TimeUnit timeUnit)

Waits until all active tasks are finished.

boolean

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

Protected methods

void
finished(Description description)
void

Called when the number of awaiting tasks reaches to 0.

void
starting(Description description)

Inherited methods

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

Public constructors

CountingTaskExecutorRule

Added in 2.0.0
public CountingTaskExecutorRule()

Public methods

drainTasks

Added in 2.0.0
public void drainTasks(int time, @NonNull TimeUnit timeUnit)

Waits until all active tasks are finished.

Parameters
int time

The duration to wait

@NonNull 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
public boolean isIdle()

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 methods

finished

protected void finished(Description description)

onIdle

Added in 2.0.0
protected void onIdle()

Called when the number of awaiting tasks reaches to 0.

See also
isIdle

starting

protected void starting(Description description)