@UnstableApi
class RobolectricUtil


Utility methods for Robolectric-based tests.

Summary

Constants

const Long

The default timeout applied when calling runMainLooperUntil.

Public functions

java-static ConditionVariable!

Creates a ConditionVariable whose block method times out according to wallclock time when used in Robolectric tests.

java-static Unit
runLooperUntil(looper: Looper!, condition: Supplier<Boolean!>!)

Runs tasks of the looper until the condition returns true.

java-static Unit
runLooperUntil(
    looper: Looper!,
    condition: Supplier<Boolean!>!,
    timeoutMs: Long,
    clock: Clock!
)

Runs tasks of the looper until the condition returns true.

java-static Unit

Runs tasks of the main Robolectric Looper until the condition returns true.

java-static Unit
runMainLooperUntil(
    condition: Supplier<Boolean!>!,
    timeoutMs: Long,
    clock: Clock!
)

Runs tasks of the main Robolectric Looper until the condition returns true.

Constants

DEFAULT_TIMEOUT_MS

const val DEFAULT_TIMEOUT_MS = 10000: Long

The default timeout applied when calling runMainLooperUntil. This timeout should be sufficient for any condition using a Robolectric test.

Public functions

createRobolectricConditionVariable

java-static fun createRobolectricConditionVariable(): ConditionVariable!

Creates a ConditionVariable whose block method times out according to wallclock time when used in Robolectric tests.

runLooperUntil

java-static fun runLooperUntil(looper: Looper!, condition: Supplier<Boolean!>!): Unit

Runs tasks of the looper until the condition returns true.

Must be called on the thread corresponding to the looper.

Parameters
looper: Looper!

The Looper.

condition: Supplier<Boolean!>!

The condition.

runLooperUntil

java-static fun runLooperUntil(
    looper: Looper!,
    condition: Supplier<Boolean!>!,
    timeoutMs: Long,
    clock: Clock!
): Unit

Runs tasks of the looper until the condition returns true.

Must be called on the thread corresponding to the looper.

Parameters
looper: Looper!

The Looper.

condition: Supplier<Boolean!>!

The condition.

timeoutMs: Long

The timeout in milliseconds.

clock: Clock!

The Clock to measure the timeout.

Throws
java.util.concurrent.TimeoutException

If the timeoutMs timeout is exceeded.

runMainLooperUntil

java-static fun runMainLooperUntil(condition: Supplier<Boolean!>!): Unit

Runs tasks of the main Robolectric Looper until the condition returns true.

Must be called on the main test thread.

Parameters
condition: Supplier<Boolean!>!

The condition.

runMainLooperUntil

java-static fun runMainLooperUntil(
    condition: Supplier<Boolean!>!,
    timeoutMs: Long,
    clock: Clock!
): Unit

Runs tasks of the main Robolectric Looper until the condition returns true.

Must be called on the main test thread.

Parameters
condition: Supplier<Boolean!>!

The condition.

timeoutMs: Long

The timeout in milliseconds.

clock: Clock!

The Clock to measure the timeout.

Throws
java.util.concurrent.TimeoutException

If the timeoutMs timeout is exceeded.