Class RobolectricUtil
- java.lang.Object
-
- com.google.android.exoplayer2.robolectric.RobolectricUtil
-
public final class RobolectricUtil extends Object
Utility methods for Robolectric-based tests.
-
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_TIMEOUT_MS
The default timeout applied when callingrunMainLooperUntil(Supplier)
.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ConditionVariable
createRobolectricConditionVariable()
Creates aConditionVariable
whoseConditionVariable.block(long)
method times out according to wallclock time when used in Robolectric tests.static void
runLooperUntil(Looper looper, Supplier<Boolean> condition)
Runs tasks of thelooper
until thecondition
returnstrue
.static void
runLooperUntil(Looper looper, Supplier<Boolean> condition, long timeoutMs, Clock clock)
Runs tasks of thelooper
until thecondition
returnstrue
.static void
runMainLooperUntil(Supplier<Boolean> condition)
static void
runMainLooperUntil(Supplier<Boolean> condition, long timeoutMs, Clock clock)
-
-
-
Field Detail
-
DEFAULT_TIMEOUT_MS
public static final long DEFAULT_TIMEOUT_MS
The default timeout applied when callingrunMainLooperUntil(Supplier)
. This timeout should be sufficient for any condition using a Robolectric test.- See Also:
- Constant Field Values
-
-
Method Detail
-
createRobolectricConditionVariable
public static ConditionVariable createRobolectricConditionVariable()
Creates aConditionVariable
whoseConditionVariable.block(long)
method times out according to wallclock time when used in Robolectric tests.
-
runMainLooperUntil
public static void runMainLooperUntil(Supplier<Boolean> condition) throws TimeoutException
Runs tasks of the main RobolectricLooper
until thecondition
returnstrue
.Must be called on the main test thread.
- Parameters:
condition
- The condition.- Throws:
TimeoutException
- If theDEFAULT_TIMEOUT_MS
is exceeded.
-
runMainLooperUntil
public static void runMainLooperUntil(Supplier<Boolean> condition, long timeoutMs, Clock clock) throws TimeoutException
Runs tasks of the main RobolectricLooper
until thecondition
returnstrue
.Must be called on the main test thread.
- Parameters:
condition
- The condition.timeoutMs
- The timeout in milliseconds.clock
- TheClock
to measure the timeout.- Throws:
TimeoutException
- If thetimeoutMs timeout
is exceeded.
-
runLooperUntil
public static void runLooperUntil(Looper looper, Supplier<Boolean> condition) throws TimeoutException
Runs tasks of thelooper
until thecondition
returnstrue
.Must be called on the thread corresponding to the
looper
.- Parameters:
looper
- TheLooper
.condition
- The condition.- Throws:
TimeoutException
- If theDEFAULT_TIMEOUT_MS
is exceeded.
-
runLooperUntil
public static void runLooperUntil(Looper looper, Supplier<Boolean> condition, long timeoutMs, Clock clock) throws TimeoutException
Runs tasks of thelooper
until thecondition
returnstrue
.Must be called on the thread corresponding to the
looper
.- Parameters:
looper
- TheLooper
.condition
- The condition.timeoutMs
- The timeout in milliseconds.clock
- TheClock
to measure the timeout.- Throws:
TimeoutException
- If thetimeoutMs timeout
is exceeded.
-
-