Test that ExoPlayer can be built in a background thread

PiperOrigin-RevId: 318264209
This commit is contained in:
krocard 2020-06-25 15:02:10 +01:00 committed by Christos Tsilopoulos
parent aaa7fd114e
commit a8ae98b1bf

View File

@ -105,6 +105,7 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;
import org.robolectric.annotation.LooperMode;
import org.robolectric.shadows.ShadowAudioManager;
@ -6766,6 +6767,20 @@ public final class ExoPlayerTest {
assertThat(initialMediaItems).containsExactlyElementsIn(currentMediaItems);
}
// TODO: Revert to @Config(sdk = Config.ALL_SDKS) once b/143232359 is resolved
@Test
@Config(minSdk = Config.OLDEST_SDK, maxSdk = Config.TARGET_SDK)
public void buildSimpleExoPlayerInBackgroundThread_doesNotThrow() throws Exception {
Thread builderThread = new Thread(() -> new SimpleExoPlayer.Builder(context).build());
AtomicReference<Throwable> builderThrow = new AtomicReference<>();
builderThread.setUncaughtExceptionHandler((thread, throwable) -> builderThrow.set(throwable));
builderThread.start();
builderThread.join();
assertThat(builderThrow.get()).isNull();
}
// Internal methods.
private static ActionSchedule.Builder addSurfaceSwitch(ActionSchedule.Builder builder) {