Tighten exception handling in TestPlayerRunHelper
This removes `throws Exception` from public methods in favour of more specific exception types (`TimeoutException` and `PlaybackException`). PiperOrigin-RevId: 637880546
This commit is contained in:
parent
0baa4ff621
commit
496bc2b058
@ -109,10 +109,15 @@ public final class TestPlayerRunHelper {
|
|||||||
* Runs tasks of the main {@link Looper} until {@link Player#getPlaybackState()} matches the
|
* Runs tasks of the main {@link Looper} until {@link Player#getPlaybackState()} matches the
|
||||||
* expected state or an error occurs.
|
* expected state or an error occurs.
|
||||||
*
|
*
|
||||||
|
* @throws PlaybackException If a fatal playback error occurs.
|
||||||
|
* @throws IllegalStateException If non-fatal playback errors occur, and aren't {@linkplain
|
||||||
|
* #ignoringNonFatalErrors() ignored} (the non-fatal exceptions will be attached with {@link
|
||||||
|
* Throwable#addSuppressed(Throwable)}).
|
||||||
* @throws TimeoutException If the {@linkplain RobolectricUtil#DEFAULT_TIMEOUT_MS default
|
* @throws TimeoutException If the {@linkplain RobolectricUtil#DEFAULT_TIMEOUT_MS default
|
||||||
* timeout} is exceeded.
|
* timeout} is exceeded.
|
||||||
*/
|
*/
|
||||||
public final void untilState(@Player.State int expectedState) throws Exception {
|
public final void untilState(@Player.State int expectedState)
|
||||||
|
throws PlaybackException, TimeoutException {
|
||||||
runUntil(() -> player.getPlaybackState() == expectedState);
|
runUntil(() -> player.getPlaybackState() == expectedState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,10 +125,15 @@ public final class TestPlayerRunHelper {
|
|||||||
* Runs tasks of the main {@link Looper} until {@link Player#getPlayWhenReady()} matches the
|
* Runs tasks of the main {@link Looper} until {@link Player#getPlayWhenReady()} matches the
|
||||||
* expected value or an error occurs.
|
* expected value or an error occurs.
|
||||||
*
|
*
|
||||||
|
* @throws PlaybackException If a playback error occurs.
|
||||||
|
* @throws IllegalStateException If non-fatal playback errors occur, and aren't {@linkplain
|
||||||
|
* #ignoringNonFatalErrors() ignored} (the non-fatal exceptions will be attached with {@link
|
||||||
|
* Throwable#addSuppressed(Throwable)}).
|
||||||
* @throws TimeoutException If the {@linkplain RobolectricUtil#DEFAULT_TIMEOUT_MS default
|
* @throws TimeoutException If the {@linkplain RobolectricUtil#DEFAULT_TIMEOUT_MS default
|
||||||
* timeout} is exceeded.
|
* timeout} is exceeded.
|
||||||
*/
|
*/
|
||||||
public final void untilPlayWhenReadyIs(boolean expectedPlayWhenReady) throws Exception {
|
public final void untilPlayWhenReadyIs(boolean expectedPlayWhenReady)
|
||||||
|
throws PlaybackException, TimeoutException {
|
||||||
runUntil(() -> player.getPlayWhenReady() == expectedPlayWhenReady);
|
runUntil(() -> player.getPlayWhenReady() == expectedPlayWhenReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,20 +141,29 @@ public final class TestPlayerRunHelper {
|
|||||||
* Runs tasks of the main {@link Looper} until {@link Player#isLoading()} matches the expected
|
* Runs tasks of the main {@link Looper} until {@link Player#isLoading()} matches the expected
|
||||||
* value or an error occurs.
|
* value or an error occurs.
|
||||||
*
|
*
|
||||||
|
* @throws PlaybackException If a playback error occurs.
|
||||||
|
* @throws IllegalStateException If non-fatal playback errors occur, and aren't {@linkplain
|
||||||
|
* #ignoringNonFatalErrors() ignored} (the non-fatal exceptions will be attached with {@link
|
||||||
|
* Throwable#addSuppressed(Throwable)}).
|
||||||
* @throws TimeoutException If the {@linkplain RobolectricUtil#DEFAULT_TIMEOUT_MS default
|
* @throws TimeoutException If the {@linkplain RobolectricUtil#DEFAULT_TIMEOUT_MS default
|
||||||
* timeout} is exceeded.
|
* timeout} is exceeded.
|
||||||
*/
|
*/
|
||||||
public final void untilLoadingIs(boolean expectedIsLoading) throws Exception {
|
public final void untilLoadingIs(boolean expectedIsLoading)
|
||||||
|
throws PlaybackException, TimeoutException {
|
||||||
runUntil(() -> player.isLoading() == expectedIsLoading);
|
runUntil(() -> player.isLoading() == expectedIsLoading);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs tasks of the main {@link Looper} until a timeline change or an error occurs.
|
* Runs tasks of the main {@link Looper} until a timeline change or an error occurs.
|
||||||
*
|
*
|
||||||
|
* @throws PlaybackException If a playback error occurs.
|
||||||
|
* @throws IllegalStateException If non-fatal playback errors occur, and aren't {@linkplain
|
||||||
|
* #ignoringNonFatalErrors() ignored} (the non-fatal exceptions will be attached with {@link
|
||||||
|
* Throwable#addSuppressed(Throwable)}).
|
||||||
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
||||||
* exceeded.
|
* exceeded.
|
||||||
*/
|
*/
|
||||||
public final Timeline untilTimelineChanges() throws Exception {
|
public final Timeline untilTimelineChanges() throws PlaybackException, TimeoutException {
|
||||||
AtomicReference<@NullableType Timeline> receivedTimeline = new AtomicReference<>();
|
AtomicReference<@NullableType Timeline> receivedTimeline = new AtomicReference<>();
|
||||||
Player.Listener listener =
|
Player.Listener listener =
|
||||||
new Player.Listener() {
|
new Player.Listener() {
|
||||||
@ -166,10 +185,15 @@ public final class TestPlayerRunHelper {
|
|||||||
* Runs tasks of the main {@link Looper} until {@link Player#getCurrentTimeline()} matches the
|
* Runs tasks of the main {@link Looper} until {@link Player#getCurrentTimeline()} matches the
|
||||||
* expected timeline or an error occurs.
|
* expected timeline or an error occurs.
|
||||||
*
|
*
|
||||||
|
* @throws PlaybackException If a playback error occurs.
|
||||||
|
* @throws IllegalStateException If non-fatal playback errors occur, and aren't {@linkplain
|
||||||
|
* #ignoringNonFatalErrors() ignored} (the non-fatal exceptions will be attached with {@link
|
||||||
|
* Throwable#addSuppressed(Throwable)}).
|
||||||
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
||||||
* exceeded.
|
* exceeded.
|
||||||
*/
|
*/
|
||||||
public final void untilTimelineChangesTo(Timeline expectedTimeline) throws Exception {
|
public final void untilTimelineChangesTo(Timeline expectedTimeline)
|
||||||
|
throws PlaybackException, TimeoutException {
|
||||||
runUntil(() -> expectedTimeline.equals(player.getCurrentTimeline()));
|
runUntil(() -> expectedTimeline.equals(player.getCurrentTimeline()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,11 +202,15 @@ public final class TestPlayerRunHelper {
|
|||||||
* Player.Listener#onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)} is
|
* Player.Listener#onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)} is
|
||||||
* called with the specified {@link Player.DiscontinuityReason} or an error occurs.
|
* called with the specified {@link Player.DiscontinuityReason} or an error occurs.
|
||||||
*
|
*
|
||||||
|
* @throws PlaybackException If a playback error occurs.
|
||||||
|
* @throws IllegalStateException If non-fatal playback errors occur, and aren't {@linkplain
|
||||||
|
* #ignoringNonFatalErrors() ignored} (the non-fatal exceptions will be attached with {@link
|
||||||
|
* Throwable#addSuppressed(Throwable)}).
|
||||||
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
||||||
* exceeded.
|
* exceeded.
|
||||||
*/
|
*/
|
||||||
public final void untilPositionDiscontinuityWithReason(
|
public final void untilPositionDiscontinuityWithReason(
|
||||||
@Player.DiscontinuityReason int expectedReason) throws Exception {
|
@Player.DiscontinuityReason int expectedReason) throws PlaybackException, TimeoutException {
|
||||||
AtomicBoolean receivedExpectedDiscontinuityReason = new AtomicBoolean(false);
|
AtomicBoolean receivedExpectedDiscontinuityReason = new AtomicBoolean(false);
|
||||||
Player.Listener listener =
|
Player.Listener listener =
|
||||||
new Player.Listener() {
|
new Player.Listener() {
|
||||||
@ -222,10 +250,14 @@ public final class TestPlayerRunHelper {
|
|||||||
* Runs tasks of the main {@link Looper} until {@link Player.Listener#onRenderedFirstFrame} is
|
* Runs tasks of the main {@link Looper} until {@link Player.Listener#onRenderedFirstFrame} is
|
||||||
* called or an error occurs.
|
* called or an error occurs.
|
||||||
*
|
*
|
||||||
|
* @throws PlaybackException If a playback error occurs.
|
||||||
|
* @throws IllegalStateException If non-fatal playback errors occur, and aren't {@linkplain
|
||||||
|
* #ignoringNonFatalErrors() ignored} (the non-fatal exceptions will be attached with {@link
|
||||||
|
* Throwable#addSuppressed(Throwable)}).
|
||||||
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
||||||
* exceeded.
|
* exceeded.
|
||||||
*/
|
*/
|
||||||
public void untilFirstFrameIsRendered() throws Exception {
|
public void untilFirstFrameIsRendered() throws PlaybackException, TimeoutException {
|
||||||
AtomicBoolean receivedFirstFrameRenderedCallback = new AtomicBoolean(false);
|
AtomicBoolean receivedFirstFrameRenderedCallback = new AtomicBoolean(false);
|
||||||
Player.Listener listener =
|
Player.Listener listener =
|
||||||
new Player.Listener() {
|
new Player.Listener() {
|
||||||
@ -257,7 +289,8 @@ public final class TestPlayerRunHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Runs the main {@link Looper} until {@code predicate} returns true or an error occurs. */
|
/** Runs the main {@link Looper} until {@code predicate} returns true or an error occurs. */
|
||||||
protected final void runUntil(Supplier<Boolean> predicate) throws Exception {
|
protected final void runUntil(Supplier<Boolean> predicate)
|
||||||
|
throws PlaybackException, TimeoutException {
|
||||||
checkState(!hasBeenUsed);
|
checkState(!hasBeenUsed);
|
||||||
hasBeenUsed = true;
|
hasBeenUsed = true;
|
||||||
ErrorListener errorListener = new ErrorListener(throwNonFatalErrors);
|
ErrorListener errorListener = new ErrorListener(throwNonFatalErrors);
|
||||||
@ -304,11 +337,15 @@ public final class TestPlayerRunHelper {
|
|||||||
* Runs tasks of the main {@link Looper} until {@link ExoPlayer#isSleepingForOffload()} matches
|
* Runs tasks of the main {@link Looper} until {@link ExoPlayer#isSleepingForOffload()} matches
|
||||||
* the expected value, or an error occurs.
|
* the expected value, or an error occurs.
|
||||||
*
|
*
|
||||||
|
* @throws PlaybackException If a playback error occurs.
|
||||||
|
* @throws IllegalStateException If non-fatal playback errors occur, and aren't {@linkplain
|
||||||
|
* #ignoringNonFatalErrors() ignored} (the non-fatal exceptions will be attached with {@link
|
||||||
|
* Throwable#addSuppressed(Throwable)}).
|
||||||
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
||||||
* exceeded.
|
* exceeded.
|
||||||
*/
|
*/
|
||||||
public void untilSleepingForOffloadBecomes(boolean expectedSleepingForOffload)
|
public void untilSleepingForOffloadBecomes(boolean expectedSleepingForOffload)
|
||||||
throws Exception {
|
throws PlaybackException, TimeoutException {
|
||||||
AtomicBoolean receivedExpectedValue = new AtomicBoolean(false);
|
AtomicBoolean receivedExpectedValue = new AtomicBoolean(false);
|
||||||
ExoPlayer.AudioOffloadListener listener =
|
ExoPlayer.AudioOffloadListener listener =
|
||||||
new ExoPlayer.AudioOffloadListener() {
|
new ExoPlayer.AudioOffloadListener() {
|
||||||
@ -336,10 +373,15 @@ public final class TestPlayerRunHelper {
|
|||||||
* chains, custom {@link RobolectricUtil#runMainLooperUntil} conditions, or an explicit {@link
|
* chains, custom {@link RobolectricUtil#runMainLooperUntil} conditions, or an explicit {@link
|
||||||
* ThreadTestUtil#unblockThreadsWaitingForProgressOnCurrentLooper()} on the main thread.
|
* ThreadTestUtil#unblockThreadsWaitingForProgressOnCurrentLooper()} on the main thread.
|
||||||
*
|
*
|
||||||
|
* @throws PlaybackException If a playback error occurs.
|
||||||
|
* @throws IllegalStateException If non-fatal playback errors occur, and aren't {@linkplain
|
||||||
|
* #ignoringNonFatalErrors() ignored} (the non-fatal exceptions will be attached with {@link
|
||||||
|
* Throwable#addSuppressed(Throwable)}).
|
||||||
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
||||||
* exceeded.
|
* exceeded.
|
||||||
*/
|
*/
|
||||||
public void untilPosition(int mediaItemIndex, long positionMs) throws Exception {
|
public void untilPosition(int mediaItemIndex, long positionMs)
|
||||||
|
throws PlaybackException, TimeoutException {
|
||||||
checkState(!hasBeenUsed);
|
checkState(!hasBeenUsed);
|
||||||
hasBeenUsed = true;
|
hasBeenUsed = true;
|
||||||
Looper applicationLooper = Util.getCurrentOrMainLooper();
|
Looper applicationLooper = Util.getCurrentOrMainLooper();
|
||||||
@ -382,10 +424,15 @@ public final class TestPlayerRunHelper {
|
|||||||
* ThreadTestUtil#unblockThreadsWaitingForProgressOnCurrentLooper()} on the main thread.
|
* ThreadTestUtil#unblockThreadsWaitingForProgressOnCurrentLooper()} on the main thread.
|
||||||
*
|
*
|
||||||
* @param mediaItemIndex The index of the media item.
|
* @param mediaItemIndex The index of the media item.
|
||||||
|
* @throws PlaybackException If a playback error occurs.
|
||||||
|
* @throws IllegalStateException If non-fatal playback errors occur, and aren't {@linkplain
|
||||||
|
* #ignoringNonFatalErrors() ignored} (the non-fatal exceptions will be attached with {@link
|
||||||
|
* Throwable#addSuppressed(Throwable)}).
|
||||||
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
||||||
* exceeded.
|
* exceeded.
|
||||||
*/
|
*/
|
||||||
public void untilStartOfMediaItem(int mediaItemIndex) throws Exception {
|
public void untilStartOfMediaItem(int mediaItemIndex)
|
||||||
|
throws PlaybackException, TimeoutException {
|
||||||
untilPosition(mediaItemIndex, /* positionMs= */ 0);
|
untilPosition(mediaItemIndex, /* positionMs= */ 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,7 +445,7 @@ public final class TestPlayerRunHelper {
|
|||||||
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
||||||
* exceeded.
|
* exceeded.
|
||||||
*/
|
*/
|
||||||
public void untilPendingCommandsAreFullyHandled() throws Exception {
|
public void untilPendingCommandsAreFullyHandled() throws TimeoutException {
|
||||||
checkState(!hasBeenUsed);
|
checkState(!hasBeenUsed);
|
||||||
hasBeenUsed = true;
|
hasBeenUsed = true;
|
||||||
// Send message to player that will arrive after all other pending commands. Thus, the message
|
// Send message to player that will arrive after all other pending commands. Thus, the message
|
||||||
@ -427,11 +474,15 @@ public final class TestPlayerRunHelper {
|
|||||||
* messages.
|
* messages.
|
||||||
*
|
*
|
||||||
* @param backgroundThreadCondition The condition to wait for.
|
* @param backgroundThreadCondition The condition to wait for.
|
||||||
|
* @throws PlaybackException If a playback error occurs.
|
||||||
|
* @throws IllegalStateException If non-fatal playback errors occur, and aren't {@linkplain
|
||||||
|
* #ignoringNonFatalErrors() ignored} (the non-fatal exceptions will be attached with {@link
|
||||||
|
* Throwable#addSuppressed(Throwable)}).
|
||||||
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
* @throws TimeoutException If the {@link RobolectricUtil#DEFAULT_TIMEOUT_MS default timeout} is
|
||||||
* exceeded.
|
* exceeded.
|
||||||
*/
|
*/
|
||||||
public void untilBackgroundThreadCondition(Supplier<Boolean> backgroundThreadCondition)
|
public void untilBackgroundThreadCondition(Supplier<Boolean> backgroundThreadCondition)
|
||||||
throws Exception {
|
throws PlaybackException, TimeoutException {
|
||||||
if (backgroundThreadCondition.get()) {
|
if (backgroundThreadCondition.get()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -515,7 +566,8 @@ public final class TestPlayerRunHelper {
|
|||||||
* Runs tasks of the main {@link Looper} until {@link Player#getPlaybackState()} matches the
|
* Runs tasks of the main {@link Looper} until {@link Player#getPlaybackState()} matches the
|
||||||
* expected state or an error occurs.
|
* expected state or an error occurs.
|
||||||
*
|
*
|
||||||
* <p>If a checked exception occurs it will be thrown wrapped in an {@link IllegalStateException}.
|
* <p>If a fatal {@link PlaybackException} occurs it will be thrown wrapped in an {@link
|
||||||
|
* IllegalStateException}.
|
||||||
*
|
*
|
||||||
* <p>New usages should prefer {@link #run(Player)} and {@link PlayerRunResult#untilState(int)}.
|
* <p>New usages should prefer {@link #run(Player)} and {@link PlayerRunResult#untilState(int)}.
|
||||||
*
|
*
|
||||||
@ -528,9 +580,7 @@ public final class TestPlayerRunHelper {
|
|||||||
throws TimeoutException {
|
throws TimeoutException {
|
||||||
try {
|
try {
|
||||||
run(player).untilState(expectedState);
|
run(player).untilState(expectedState);
|
||||||
} catch (RuntimeException | TimeoutException e) {
|
} catch (PlaybackException e) {
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -539,7 +589,8 @@ public final class TestPlayerRunHelper {
|
|||||||
* Runs tasks of the main {@link Looper} until {@link Player#getPlayWhenReady()} matches the
|
* Runs tasks of the main {@link Looper} until {@link Player#getPlayWhenReady()} matches the
|
||||||
* expected value or an error occurs.
|
* expected value or an error occurs.
|
||||||
*
|
*
|
||||||
* <p>If a checked exception occurs it will be thrown wrapped in an {@link IllegalStateException}.
|
* <p>If a fatal {@link PlaybackException} occurs it will be thrown wrapped in an {@link
|
||||||
|
* IllegalStateException}.
|
||||||
*
|
*
|
||||||
* <p>New usages should prefer {@link #run(Player)} and {@link
|
* <p>New usages should prefer {@link #run(Player)} and {@link
|
||||||
* PlayerRunResult#untilPlayWhenReadyIs(boolean)}.
|
* PlayerRunResult#untilPlayWhenReadyIs(boolean)}.
|
||||||
@ -553,9 +604,7 @@ public final class TestPlayerRunHelper {
|
|||||||
throws TimeoutException {
|
throws TimeoutException {
|
||||||
try {
|
try {
|
||||||
run(player).untilPlayWhenReadyIs(expectedPlayWhenReady);
|
run(player).untilPlayWhenReadyIs(expectedPlayWhenReady);
|
||||||
} catch (RuntimeException | TimeoutException e) {
|
} catch (PlaybackException e) {
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -564,7 +613,8 @@ public final class TestPlayerRunHelper {
|
|||||||
* Runs tasks of the main {@link Looper} until {@link Player#isLoading()} matches the expected
|
* Runs tasks of the main {@link Looper} until {@link Player#isLoading()} matches the expected
|
||||||
* value or an error occurs.
|
* value or an error occurs.
|
||||||
*
|
*
|
||||||
* <p>If a checked exception occurs it will be thrown wrapped in an {@link IllegalStateException}.
|
* <p>If a fatal {@link PlaybackException} occurs it will be thrown wrapped in an {@link
|
||||||
|
* IllegalStateException}.
|
||||||
*
|
*
|
||||||
* <p>New usages should prefer {@link #run(Player)} and {@link
|
* <p>New usages should prefer {@link #run(Player)} and {@link
|
||||||
* PlayerRunResult#untilLoadingIs(boolean)}.
|
* PlayerRunResult#untilLoadingIs(boolean)}.
|
||||||
@ -578,9 +628,7 @@ public final class TestPlayerRunHelper {
|
|||||||
throws TimeoutException {
|
throws TimeoutException {
|
||||||
try {
|
try {
|
||||||
run(player).untilLoadingIs(expectedIsLoading);
|
run(player).untilLoadingIs(expectedIsLoading);
|
||||||
} catch (RuntimeException | TimeoutException e) {
|
} catch (PlaybackException e) {
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -589,7 +637,8 @@ public final class TestPlayerRunHelper {
|
|||||||
* Runs tasks of the main {@link Looper} until {@link Player#getCurrentTimeline()} matches the
|
* Runs tasks of the main {@link Looper} until {@link Player#getCurrentTimeline()} matches the
|
||||||
* expected timeline or an error occurs.
|
* expected timeline or an error occurs.
|
||||||
*
|
*
|
||||||
* <p>If a checked exception occurs it will be thrown wrapped in an {@link IllegalStateException}.
|
* <p>If a fatal {@link PlaybackException} occurs it will be thrown wrapped in an {@link
|
||||||
|
* IllegalStateException}.
|
||||||
*
|
*
|
||||||
* <p>New usages should prefer {@link #run(Player)} and {@link
|
* <p>New usages should prefer {@link #run(Player)} and {@link
|
||||||
* PlayerRunResult#untilTimelineChangesTo(Timeline)}.
|
* PlayerRunResult#untilTimelineChangesTo(Timeline)}.
|
||||||
@ -603,9 +652,7 @@ public final class TestPlayerRunHelper {
|
|||||||
throws TimeoutException {
|
throws TimeoutException {
|
||||||
try {
|
try {
|
||||||
run(player).untilTimelineChangesTo(expectedTimeline);
|
run(player).untilTimelineChangesTo(expectedTimeline);
|
||||||
} catch (RuntimeException | TimeoutException e) {
|
} catch (PlaybackException e) {
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -613,7 +660,8 @@ public final class TestPlayerRunHelper {
|
|||||||
/**
|
/**
|
||||||
* Runs tasks of the main {@link Looper} until a timeline change or an error occurs.
|
* Runs tasks of the main {@link Looper} until a timeline change or an error occurs.
|
||||||
*
|
*
|
||||||
* <p>If a checked exception occurs it will be thrown wrapped in an {@link IllegalStateException}.
|
* <p>If a fatal {@link PlaybackException} occurs it will be thrown wrapped in an {@link
|
||||||
|
* IllegalStateException}.
|
||||||
*
|
*
|
||||||
* <p>New usages should prefer {@link #run(Player)} and {@link
|
* <p>New usages should prefer {@link #run(Player)} and {@link
|
||||||
* PlayerRunResult#untilTimelineChanges()}.
|
* PlayerRunResult#untilTimelineChanges()}.
|
||||||
@ -626,9 +674,7 @@ public final class TestPlayerRunHelper {
|
|||||||
public static Timeline runUntilTimelineChanged(Player player) throws TimeoutException {
|
public static Timeline runUntilTimelineChanged(Player player) throws TimeoutException {
|
||||||
try {
|
try {
|
||||||
return run(player).untilTimelineChanges();
|
return run(player).untilTimelineChanges();
|
||||||
} catch (RuntimeException | TimeoutException e) {
|
} catch (PlaybackException e) {
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -638,7 +684,8 @@ public final class TestPlayerRunHelper {
|
|||||||
* Player.Listener#onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)} is
|
* Player.Listener#onPositionDiscontinuity(Player.PositionInfo, Player.PositionInfo, int)} is
|
||||||
* called with the specified {@link Player.DiscontinuityReason} or an error occurs.
|
* called with the specified {@link Player.DiscontinuityReason} or an error occurs.
|
||||||
*
|
*
|
||||||
* <p>If a checked exception occurs it will be thrown wrapped in an {@link IllegalStateException}.
|
* <p>If a fatal {@link PlaybackException} occurs it will be thrown wrapped in an {@link
|
||||||
|
* IllegalStateException}.
|
||||||
*
|
*
|
||||||
* <p>New usages should prefer {@link #run(Player)} and {@link
|
* <p>New usages should prefer {@link #run(Player)} and {@link
|
||||||
* PlayerRunResult#untilPositionDiscontinuityWithReason(int)}.
|
* PlayerRunResult#untilPositionDiscontinuityWithReason(int)}.
|
||||||
@ -652,9 +699,7 @@ public final class TestPlayerRunHelper {
|
|||||||
Player player, @Player.DiscontinuityReason int expectedReason) throws TimeoutException {
|
Player player, @Player.DiscontinuityReason int expectedReason) throws TimeoutException {
|
||||||
try {
|
try {
|
||||||
run(player).untilPositionDiscontinuityWithReason(expectedReason);
|
run(player).untilPositionDiscontinuityWithReason(expectedReason);
|
||||||
} catch (RuntimeException | TimeoutException e) {
|
} catch (PlaybackException e) {
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -680,7 +725,8 @@ public final class TestPlayerRunHelper {
|
|||||||
* Runs tasks of the main {@link Looper} until {@link ExoPlayer#isSleepingForOffload()} matches
|
* Runs tasks of the main {@link Looper} until {@link ExoPlayer#isSleepingForOffload()} matches
|
||||||
* the expected value, or an error occurs.
|
* the expected value, or an error occurs.
|
||||||
*
|
*
|
||||||
* <p>If a checked exception occurs it will be thrown wrapped in an {@link IllegalStateException}.
|
* <p>If a fatal {@link PlaybackException} occurs it will be thrown wrapped in an {@link
|
||||||
|
* IllegalStateException}.
|
||||||
*
|
*
|
||||||
* <p>New usages should prefer {@link #run(ExoPlayer)} and {@link
|
* <p>New usages should prefer {@link #run(ExoPlayer)} and {@link
|
||||||
* ExoPlayerRunResult#untilSleepingForOffloadBecomes(boolean)}.
|
* ExoPlayerRunResult#untilSleepingForOffloadBecomes(boolean)}.
|
||||||
@ -694,9 +740,7 @@ public final class TestPlayerRunHelper {
|
|||||||
throws TimeoutException {
|
throws TimeoutException {
|
||||||
try {
|
try {
|
||||||
run(player).untilSleepingForOffloadBecomes(expectedSleepForOffload);
|
run(player).untilSleepingForOffloadBecomes(expectedSleepForOffload);
|
||||||
} catch (RuntimeException | TimeoutException e) {
|
} catch (PlaybackException e) {
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -705,7 +749,8 @@ public final class TestPlayerRunHelper {
|
|||||||
* Runs tasks of the main {@link Looper} until {@link Player.Listener#onRenderedFirstFrame} is
|
* Runs tasks of the main {@link Looper} until {@link Player.Listener#onRenderedFirstFrame} is
|
||||||
* called or an error occurs.
|
* called or an error occurs.
|
||||||
*
|
*
|
||||||
* <p>If a checked exception occurs it will be thrown wrapped in an {@link IllegalStateException}.
|
* <p>If a fatal {@link PlaybackException} occurs it will be thrown wrapped in an {@link
|
||||||
|
* IllegalStateException}.
|
||||||
*
|
*
|
||||||
* <p>New usages should prefer {@link #run(Player)} and {@link
|
* <p>New usages should prefer {@link #run(Player)} and {@link
|
||||||
* PlayerRunResult#untilFirstFrameIsRendered()}.
|
* PlayerRunResult#untilFirstFrameIsRendered()}.
|
||||||
@ -717,9 +762,7 @@ public final class TestPlayerRunHelper {
|
|||||||
public static void runUntilRenderedFirstFrame(ExoPlayer player) throws TimeoutException {
|
public static void runUntilRenderedFirstFrame(ExoPlayer player) throws TimeoutException {
|
||||||
try {
|
try {
|
||||||
run(player).untilFirstFrameIsRendered();
|
run(player).untilFirstFrameIsRendered();
|
||||||
} catch (RuntimeException | TimeoutException e) {
|
} catch (PlaybackException e) {
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -733,7 +776,8 @@ public final class TestPlayerRunHelper {
|
|||||||
* {@link RobolectricUtil#runMainLooperUntil} conditions or an explicit {@link
|
* {@link RobolectricUtil#runMainLooperUntil} conditions or an explicit {@link
|
||||||
* ThreadTestUtil#unblockThreadsWaitingForProgressOnCurrentLooper()} on the main thread.
|
* ThreadTestUtil#unblockThreadsWaitingForProgressOnCurrentLooper()} on the main thread.
|
||||||
*
|
*
|
||||||
* <p>If a checked exception occurs it will be thrown wrapped in an {@link IllegalStateException}.
|
* <p>If a fatal {@link PlaybackException} occurs it will be thrown wrapped in an {@link
|
||||||
|
* IllegalStateException}.
|
||||||
*
|
*
|
||||||
* <p>New usages should prefer {@link #run(ExoPlayer)} and {@link
|
* <p>New usages should prefer {@link #run(ExoPlayer)} and {@link
|
||||||
* ExoPlayerRunResult#untilPosition(int, long)}.
|
* ExoPlayerRunResult#untilPosition(int, long)}.
|
||||||
@ -748,9 +792,7 @@ public final class TestPlayerRunHelper {
|
|||||||
throws TimeoutException {
|
throws TimeoutException {
|
||||||
try {
|
try {
|
||||||
play(player).untilPosition(mediaItemIndex, positionMs);
|
play(player).untilPosition(mediaItemIndex, positionMs);
|
||||||
} catch (RuntimeException | TimeoutException e) {
|
} catch (PlaybackException e) {
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -764,7 +806,8 @@ public final class TestPlayerRunHelper {
|
|||||||
* {@link RobolectricUtil#runMainLooperUntil} conditions or an explicit {@link
|
* {@link RobolectricUtil#runMainLooperUntil} conditions or an explicit {@link
|
||||||
* ThreadTestUtil#unblockThreadsWaitingForProgressOnCurrentLooper()} on the main thread.
|
* ThreadTestUtil#unblockThreadsWaitingForProgressOnCurrentLooper()} on the main thread.
|
||||||
*
|
*
|
||||||
* <p>If a checked exception occurs it will be thrown wrapped in an {@link IllegalStateException}.
|
* <p>If a fatal {@link PlaybackException} occurs it will be thrown wrapped in an {@link
|
||||||
|
* IllegalStateException}.
|
||||||
*
|
*
|
||||||
* <p>New usages should prefer {@link #run(ExoPlayer)} and {@link
|
* <p>New usages should prefer {@link #run(ExoPlayer)} and {@link
|
||||||
* ExoPlayerRunResult#untilStartOfMediaItem(int)}.
|
* ExoPlayerRunResult#untilStartOfMediaItem(int)}.
|
||||||
@ -778,9 +821,7 @@ public final class TestPlayerRunHelper {
|
|||||||
throws TimeoutException {
|
throws TimeoutException {
|
||||||
try {
|
try {
|
||||||
play(player).untilStartOfMediaItem(mediaItemIndex);
|
play(player).untilStartOfMediaItem(mediaItemIndex);
|
||||||
} catch (RuntimeException | TimeoutException e) {
|
} catch (PlaybackException e) {
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -797,13 +838,7 @@ public final class TestPlayerRunHelper {
|
|||||||
*/
|
*/
|
||||||
public static void runUntilPendingCommandsAreFullyHandled(ExoPlayer player)
|
public static void runUntilPendingCommandsAreFullyHandled(ExoPlayer player)
|
||||||
throws TimeoutException {
|
throws TimeoutException {
|
||||||
try {
|
|
||||||
run(player).untilPendingCommandsAreFullyHandled();
|
run(player).untilPendingCommandsAreFullyHandled();
|
||||||
} catch (RuntimeException | TimeoutException e) {
|
|
||||||
throw e;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new IllegalStateException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void verifyMainTestThread(Player player) {
|
private static void verifyMainTestThread(Player player) {
|
||||||
@ -827,7 +862,7 @@ public final class TestPlayerRunHelper {
|
|||||||
private static final class ErrorListener implements AnalyticsListener, Player.Listener {
|
private static final class ErrorListener implements AnalyticsListener, Player.Listener {
|
||||||
|
|
||||||
@Nullable private final List<Exception> nonFatalErrors;
|
@Nullable private final List<Exception> nonFatalErrors;
|
||||||
private @MonotonicNonNull Exception fatalError;
|
private @MonotonicNonNull PlaybackException fatalError;
|
||||||
|
|
||||||
public ErrorListener(boolean throwNonFatalErrors) {
|
public ErrorListener(boolean throwNonFatalErrors) {
|
||||||
if (throwNonFatalErrors) {
|
if (throwNonFatalErrors) {
|
||||||
@ -841,7 +876,7 @@ public final class TestPlayerRunHelper {
|
|||||||
return fatalError != null;
|
return fatalError != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void maybeThrow() throws Exception {
|
public void maybeThrow() throws PlaybackException {
|
||||||
if (fatalError != null) {
|
if (fatalError != null) {
|
||||||
throw fatalError;
|
throw fatalError;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user