Package com.google.android.exoplayer2.robolectric

## 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 calling `runMainLooperUntil(Supplier)`.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static ConditionVariable` | `createRobolectricConditionVariable()` | Creates a `ConditionVariable` whose `ConditionVariable.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 the `looper` until the `condition` returns `true`.
    `static void` | `runLooperUntil​(Looper looper, Supplier<Boolean> condition, long timeoutMs, Clock clock)` | Runs tasks of the `looper` until the `condition` returns `true`.
    `static void` | `runMainLooperUntil​(Supplier<Boolean> condition)` | Runs tasks of the main Robolectric `Looper` until the `condition` returns `true`.
    `static void` | `runMainLooperUntil​(Supplier<Boolean> condition, long timeoutMs, Clock clock)` | Runs tasks of the main Robolectric `Looper` until the `condition` returns `true`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_TIMEOUT_MS

          public static final long DEFAULT_TIMEOUT_MS

      The default timeout applied when calling `runMainLooperUntil(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 a `ConditionVariable` whose `ConditionVariable.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 Robolectric `Looper` until the `condition` returns `true`.

      Must be called on the main test thread.

      Parameters:
        `condition` - The condition.
      Throws:
        `TimeoutException` - If the `DEFAULT_TIMEOUT_MS` is exceeded.

    - #### runMainLooperUntil

          public static void runMainLooperUntil​(Supplier<Boolean> condition,
                                                long timeoutMs,
                                                Clock clock)
                                         throws TimeoutException

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

      Must be called on the main test thread.

      Parameters:
        `condition` - The condition.
        `timeoutMs` - The timeout in milliseconds.
        `clock` - The `Clock` to measure the timeout.
      Throws:
        `TimeoutException` - If the `timeoutMs timeout` is exceeded.

    - #### runLooperUntil

          public static void runLooperUntil​(Looper looper,
                                            Supplier<Boolean> condition)
                                     throws TimeoutException

      Runs tasks of the `looper` until the `condition` returns `true`.

      Must be called on the thread corresponding to the `looper`.

      Parameters:
        `looper` - The `Looper`.
        `condition` - The condition.
      Throws:
        `TimeoutException` - If the `DEFAULT_TIMEOUT_MS` is exceeded.

    - #### runLooperUntil

          public static void runLooperUntil​(Looper looper,
                                            Supplier<Boolean> condition,
                                            long timeoutMs,
                                            Clock clock)
                                     throws TimeoutException

      Runs tasks of the `looper` until the `condition` returns `true`.

      Must be called on the thread corresponding to the `looper`.

      Parameters:
        `looper` - The `Looper`.
        `condition` - The condition.
        `timeoutMs` - The timeout in milliseconds.
        `clock` - The `Clock` to measure the timeout.
      Throws:
        `TimeoutException` - If the `timeoutMs timeout` is exceeded.