diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/amr/AmrExtractorTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/amr/AmrExtractorNonParameterizedTest.java similarity index 80% rename from library/extractor/src/test/java/com/google/android/exoplayer2/extractor/amr/AmrExtractorTest.java rename to library/extractor/src/test/java/com/google/android/exoplayer2/extractor/amr/AmrExtractorNonParameterizedTest.java index fb81b6ed48..65b8122c4a 100644 --- a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/amr/AmrExtractorTest.java +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/amr/AmrExtractorNonParameterizedTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 The Android Open Source Project + * Copyright (C) 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. @@ -12,6 +12,7 @@ * 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.extractor.amr; @@ -22,6 +23,7 @@ import static com.google.android.exoplayer2.extractor.amr.AmrExtractor.frameSize import static com.google.common.truth.Truth.assertThat; import static junit.framework.Assert.fail; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.ParserException; import com.google.android.exoplayer2.extractor.Extractor; import com.google.android.exoplayer2.extractor.PositionHolder; @@ -30,29 +32,21 @@ import com.google.android.exoplayer2.testutil.FakeExtractorInput; import com.google.android.exoplayer2.testutil.FakeExtractorOutput; import com.google.android.exoplayer2.util.Util; import java.io.IOException; -import java.util.List; import java.util.Random; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.ParameterizedRobolectricTestRunner; -import org.robolectric.ParameterizedRobolectricTestRunner.Parameter; -import org.robolectric.ParameterizedRobolectricTestRunner.Parameters; -/** Unit test for {@link AmrExtractor}. */ -// TODO(ibaker): Split this into two test classes: one parameterized, and one not. -@RunWith(ParameterizedRobolectricTestRunner.class) -public final class AmrExtractorTest { +/** + * Tests for {@link AmrExtractor} that test specific behaviours and don't need to be parameterized. + * + *

For parameterized tests using {@link ExtractorAsserts} see {@link + * AmrExtractorParameterizedTest}. + */ +@RunWith(AndroidJUnit4.class) +public final class AmrExtractorNonParameterizedTest { private static final Random RANDOM = new Random(1234); - @Parameters(name = "{0}") - public static List params() { - return ExtractorAsserts.configs(); - } - - @Parameter(0) - public ExtractorAsserts.Config assertionConfig; - @Test public void sniff_nonAmrSignature_returnFalse() throws IOException { AmrExtractor amrExtractor = setupAmrExtractorWithOutput(); @@ -181,34 +175,6 @@ public final class AmrExtractorTest { } } - @Test - public void extractingNarrowBandSamples() throws Exception { - ExtractorAsserts.assertBehavior( - createAmrExtractorFactory(/* withSeeking= */ false), "amr/sample_nb.amr", assertionConfig); - } - - @Test - public void extractingWideBandSamples() throws Exception { - ExtractorAsserts.assertBehavior( - createAmrExtractorFactory(/* withSeeking= */ false), "amr/sample_wb.amr", assertionConfig); - } - - @Test - public void extractingNarrowBandSamples_withSeeking() throws Exception { - ExtractorAsserts.assertBehavior( - createAmrExtractorFactory(/* withSeeking= */ true), - "amr/sample_nb_cbr.amr", - assertionConfig); - } - - @Test - public void extractingWideBandSamples_withSeeking() throws Exception { - ExtractorAsserts.assertBehavior( - createAmrExtractorFactory(/* withSeeking= */ true), - "amr/sample_wb_cbr.amr", - assertionConfig); - } - private byte[] newWideBandAmrFrameWithType(int frameType) { byte frameHeader = (byte) ((frameType << 3) & (0b01111100)); int frameContentInBytes = frameSizeBytesByTypeWb(frameType) - 1; @@ -253,14 +219,4 @@ public final class AmrExtractorTest { private static FakeExtractorInput fakeExtractorInputWithData(byte[] data) { return new FakeExtractorInput.Builder().setData(data).build(); } - - private static ExtractorAsserts.ExtractorFactory createAmrExtractorFactory(boolean withSeeking) { - return () -> { - if (!withSeeking) { - return new AmrExtractor(); - } else { - return new AmrExtractor(AmrExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING); - } - }; - } } diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/amr/AmrExtractorParameterizedTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/amr/AmrExtractorParameterizedTest.java new file mode 100644 index 0000000000..833567cc9e --- /dev/null +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/amr/AmrExtractorParameterizedTest.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2018 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.extractor.amr; + +import com.google.android.exoplayer2.testutil.ExtractorAsserts; +import java.util.List; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.ParameterizedRobolectricTestRunner; +import org.robolectric.ParameterizedRobolectricTestRunner.Parameter; +import org.robolectric.ParameterizedRobolectricTestRunner.Parameters; + +/** + * Unit tests for {@link AmrExtractor} that use parameterization to test a range of behaviours. + * + *

For non-parameterized tests see {@link AmrExtractorSeekTest} and {@link + * AmrExtractorNonParameterizedTest}. + */ +@RunWith(ParameterizedRobolectricTestRunner.class) +public final class AmrExtractorParameterizedTest { + + @Parameters(name = "{0}") + public static List params() { + return ExtractorAsserts.configs(); + } + + @Parameter(0) + public ExtractorAsserts.Config assertionConfig; + + @Test + public void extractingNarrowBandSamples() throws Exception { + ExtractorAsserts.assertBehavior( + createAmrExtractorFactory(/* withSeeking= */ false), "amr/sample_nb.amr", assertionConfig); + } + + @Test + public void extractingWideBandSamples() throws Exception { + ExtractorAsserts.assertBehavior( + createAmrExtractorFactory(/* withSeeking= */ false), "amr/sample_wb.amr", assertionConfig); + } + + @Test + public void extractingNarrowBandSamples_withSeeking() throws Exception { + ExtractorAsserts.assertBehavior( + createAmrExtractorFactory(/* withSeeking= */ true), + "amr/sample_nb_cbr.amr", + assertionConfig); + } + + @Test + public void extractingWideBandSamples_withSeeking() throws Exception { + ExtractorAsserts.assertBehavior( + createAmrExtractorFactory(/* withSeeking= */ true), + "amr/sample_wb_cbr.amr", + assertionConfig); + } + + + private static ExtractorAsserts.ExtractorFactory createAmrExtractorFactory(boolean withSeeking) { + return () -> { + if (!withSeeking) { + return new AmrExtractor(); + } else { + return new AmrExtractor(AmrExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING); + } + }; + } +} diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/amr/AmrExtractorSeekTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/amr/AmrExtractorSeekTest.java index 850321ef5d..42e9f93c00 100644 --- a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/amr/AmrExtractorSeekTest.java +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/amr/AmrExtractorSeekTest.java @@ -33,7 +33,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -/** Unit test for {@link AmrExtractor}. */ +/** Unit tests for {@link AmrExtractor} seeking behaviour. */ @RunWith(AndroidJUnit4.class) public final class AmrExtractorSeekTest { diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/ogg/OggExtractorTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/ogg/OggExtractorNonParameterizedTest.java similarity index 67% rename from library/extractor/src/test/java/com/google/android/exoplayer2/extractor/ogg/OggExtractorTest.java rename to library/extractor/src/test/java/com/google/android/exoplayer2/extractor/ogg/OggExtractorNonParameterizedTest.java index 1cff207d65..bf2a350aae 100644 --- a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/ogg/OggExtractorTest.java +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/ogg/OggExtractorNonParameterizedTest.java @@ -18,50 +18,21 @@ package com.google.android.exoplayer2.extractor.ogg; import static com.google.android.exoplayer2.testutil.TestUtil.getByteArray; import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.testutil.ExtractorAsserts; import com.google.android.exoplayer2.testutil.FakeExtractorInput; import java.io.IOException; -import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.ParameterizedRobolectricTestRunner; -import org.robolectric.ParameterizedRobolectricTestRunner.Parameter; -import org.robolectric.ParameterizedRobolectricTestRunner.Parameters; -/** Unit test for {@link OggExtractor}. */ -// TODO(ibaker): Split this into OggExtractorSniffTest and OggExtractorTest after parameterization, -// otherwise we'll be running all the sniff tests multiple times. -@RunWith(ParameterizedRobolectricTestRunner.class) -public final class OggExtractorTest { - - @Parameters(name = "{0}") - public static List params() { - return ExtractorAsserts.configs(); - } - - @Parameter(0) - public ExtractorAsserts.Config assertionConfig; - - @Test - public void opus() throws Exception { - ExtractorAsserts.assertBehavior(OggExtractor::new, "ogg/bear.opus", assertionConfig); - } - - @Test - public void flac() throws Exception { - ExtractorAsserts.assertBehavior(OggExtractor::new, "ogg/bear_flac.ogg", assertionConfig); - } - - @Test - public void flacNoSeektable() throws Exception { - ExtractorAsserts.assertBehavior( - OggExtractor::new, "ogg/bear_flac_noseektable.ogg", assertionConfig); - } - - @Test - public void vorbis() throws Exception { - ExtractorAsserts.assertBehavior(OggExtractor::new, "ogg/bear_vorbis.ogg", assertionConfig); - } +/** + * Tests for {@link OggExtractor} that test specific behaviours and don't need to be parameterized. + * + *

For parameterized tests using {@link ExtractorAsserts} see {@link + * OggExtractorParameterizedTest}. + */ +@RunWith(AndroidJUnit4.class) +public final class OggExtractorNonParameterizedTest { @Test public void sniffVorbis() throws Exception { diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/ogg/OggExtractorParameterizedTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/ogg/OggExtractorParameterizedTest.java new file mode 100644 index 0000000000..2235539724 --- /dev/null +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/ogg/OggExtractorParameterizedTest.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2016 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.extractor.ogg; + +import com.google.android.exoplayer2.testutil.ExtractorAsserts; +import java.util.List; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.ParameterizedRobolectricTestRunner; +import org.robolectric.ParameterizedRobolectricTestRunner.Parameter; +import org.robolectric.ParameterizedRobolectricTestRunner.Parameters; + +/** + * Unit tests for {@link OggExtractor} that use parameterization to test a range of behaviours. + * + *

For non-parameterized tests see {@link OggExtractorNonParameterizedTest}. + */ +@RunWith(ParameterizedRobolectricTestRunner.class) +public final class OggExtractorParameterizedTest { + + @Parameters(name = "{0}") + public static List params() { + return ExtractorAsserts.configs(); + } + + @Parameter(0) + public ExtractorAsserts.Config assertionConfig; + + @Test + public void opus() throws Exception { + ExtractorAsserts.assertBehavior(OggExtractor::new, "ogg/bear.opus", assertionConfig); + } + + @Test + public void flac() throws Exception { + ExtractorAsserts.assertBehavior(OggExtractor::new, "ogg/bear_flac.ogg", assertionConfig); + } + + @Test + public void flacNoSeektable() throws Exception { + ExtractorAsserts.assertBehavior( + OggExtractor::new, "ogg/bear_flac_noseektable.ogg", assertionConfig); + } + + @Test + public void vorbis() throws Exception { + ExtractorAsserts.assertBehavior(OggExtractor::new, "ogg/bear_vorbis.ogg", assertionConfig); + } +}