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 longDEFAULT_TIMEOUT_MSThe default timeout applied when callingrunMainLooperUntil(Supplier).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ConditionVariablecreateRobolectricConditionVariable()Creates aConditionVariablewhoseConditionVariable.block(long)method times out according to wallclock time when used in Robolectric tests.static voidrunLooperUntil(Looper looper, Supplier<Boolean> condition)Runs tasks of thelooperuntil theconditionreturnstrue.static voidrunLooperUntil(Looper looper, Supplier<Boolean> condition, long timeoutMs, Clock clock)Runs tasks of thelooperuntil theconditionreturnstrue.static voidrunMainLooperUntil(Supplier<Boolean> condition)static voidrunMainLooperUntil(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 aConditionVariablewhoseConditionVariable.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 RobolectricLooperuntil theconditionreturnstrue.Must be called on the main test thread.
- Parameters:
condition- The condition.- Throws:
TimeoutException- If theDEFAULT_TIMEOUT_MSis exceeded.
-
runMainLooperUntil
public static void runMainLooperUntil(Supplier<Boolean> condition, long timeoutMs, Clock clock) throws TimeoutException
Runs tasks of the main RobolectricLooperuntil theconditionreturnstrue.Must be called on the main test thread.
- Parameters:
condition- The condition.timeoutMs- The timeout in milliseconds.clock- TheClockto measure the timeout.- Throws:
TimeoutException- If thetimeoutMs timeoutis exceeded.
-
runLooperUntil
public static void runLooperUntil(Looper looper, Supplier<Boolean> condition) throws TimeoutException
Runs tasks of thelooperuntil theconditionreturnstrue.Must be called on the thread corresponding to the
looper.- Parameters:
looper- TheLooper.condition- The condition.- Throws:
TimeoutException- If theDEFAULT_TIMEOUT_MSis exceeded.
-
runLooperUntil
public static void runLooperUntil(Looper looper, Supplier<Boolean> condition, long timeoutMs, Clock clock) throws TimeoutException
Runs tasks of thelooperuntil theconditionreturnstrue.Must be called on the thread corresponding to the
looper.- Parameters:
looper- TheLooper.condition- The condition.timeoutMs- The timeout in milliseconds.clock- TheClockto measure the timeout.- Throws:
TimeoutException- If thetimeoutMs timeoutis exceeded.
-
-