@UnstableApi
public final class DummyMainThread


Helper class to simulate main/UI thread in tests.

Summary

Nested types

Runnable variant which can throw a checked exception.

Constants

static final int
TIMEOUT_MS = 10000

Default timeout value used for runOnMainThread.

Public constructors

Public methods

void
void

Runs the provided Runnable on the main thread, blocking until execution completes or until TIMEOUT_MS milliseconds have passed.

void
runOnMainThread(int timeoutMs, Runnable runnable)

Runs the provided Runnable on the main thread, blocking until execution completes or until timeout milliseconds have passed.

void

Runs the provided TestRunnable on the main thread, blocking until execution completes or until TIMEOUT_MS milliseconds have passed.

void
runTestOnMainThread(
    int timeoutMs,
    DummyMainThread.TestRunnable runnable
)

Runs the provided TestRunnable on the main thread, blocking until execution completes or until timeout milliseconds have passed.

Constants

TIMEOUT_MS

public static final int TIMEOUT_MS = 10000

Default timeout value used for runOnMainThread.

Public constructors

DummyMainThread

public DummyMainThread()

Public methods

release

public void release()

runOnMainThread

public void runOnMainThread(Runnable runnable)

Runs the provided Runnable on the main thread, blocking until execution completes or until TIMEOUT_MS milliseconds have passed.

Parameters
Runnable runnable

The Runnable to run.

runOnMainThread

public void runOnMainThread(int timeoutMs, Runnable runnable)

Runs the provided Runnable on the main thread, blocking until execution completes or until timeout milliseconds have passed.

Parameters
int timeoutMs

The maximum time to wait in milliseconds.

Runnable runnable

The Runnable to run.

runTestOnMainThread

public void runTestOnMainThread(DummyMainThread.TestRunnable runnable)

Runs the provided TestRunnable on the main thread, blocking until execution completes or until TIMEOUT_MS milliseconds have passed.

Parameters
DummyMainThread.TestRunnable runnable

The TestRunnable to run.

runTestOnMainThread

public void runTestOnMainThread(
    int timeoutMs,
    DummyMainThread.TestRunnable runnable
)

Runs the provided TestRunnable on the main thread, blocking until execution completes or until timeout milliseconds have passed.

Parameters
int timeoutMs

The maximum time to wait in milliseconds.

DummyMainThread.TestRunnable runnable

The TestRunnable to run.