From 6884dfb313e5cb718a6f87ca4bcb25bf65609865 Mon Sep 17 00:00:00 2001 From: bachinger Date: Mon, 29 Jun 2020 11:58:13 +0100 Subject: [PATCH] Move SimpleExoPlayer.Builder unit test to a separate class PiperOrigin-RevId: 318785458 --- .../android/exoplayer2/ExoPlayerTest.java | 15 ------ .../exoplayer2/SimpleExoPlayerTest.java | 46 +++++++++++++++++++ 2 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 library/core/src/test/java/com/google/android/exoplayer2/SimpleExoPlayerTest.java diff --git a/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java b/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java index 6397df6716..30af89dd08 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java @@ -105,7 +105,6 @@ 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; @@ -6767,20 +6766,6 @@ 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 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) { diff --git a/library/core/src/test/java/com/google/android/exoplayer2/SimpleExoPlayerTest.java b/library/core/src/test/java/com/google/android/exoplayer2/SimpleExoPlayerTest.java new file mode 100644 index 0000000000..e3a625a3ce --- /dev/null +++ b/library/core/src/test/java/com/google/android/exoplayer2/SimpleExoPlayerTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.android.exoplayer2; + +import static com.google.common.truth.Truth.assertThat; + +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import java.util.concurrent.atomic.AtomicReference; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.annotation.Config; + +/** Unit test for {@link SimpleExoPlayer}. */ +@RunWith(AndroidJUnit4.class) +public class SimpleExoPlayerTest { + + // TODO(b/143232359): Revert to @Config(sdk = Config.ALL_SDKS) once b/143232359 is resolved + @Test + @Config(minSdk = Config.OLDEST_SDK, maxSdk = Config.TARGET_SDK) + public void builder_inBackgroundThread_doesNotThrow() throws Exception { + Thread builderThread = + new Thread( + () -> new SimpleExoPlayer.Builder(ApplicationProvider.getApplicationContext()).build()); + AtomicReference builderThrow = new AtomicReference<>(); + builderThread.setUncaughtExceptionHandler((thread, throwable) -> builderThrow.set(throwable)); + + builderThread.start(); + builderThread.join(); + + assertThat(builderThrow.get()).isNull(); + } +}