From 0e6b318138c0d90bc18d635b49f09a4e02eba30b Mon Sep 17 00:00:00 2001 From: ibaker Date: Fri, 24 Apr 2020 11:46:09 +0100 Subject: [PATCH] Remove ExtractorAsserts overloads that take a Context Also mark the two assertOutput methods private, to make the API surface smaller. PiperOrigin-RevId: 308228186 --- .../ext/flac/FlacExtractorTest.java | 11 ---- .../extractor/flac/FlacExtractorTest.java | 11 ---- .../extractor/mp3/Mp3ExtractorTest.java | 3 - .../extractor/ts/TsExtractorTest.java | 6 +- .../extractor/wav/WavExtractorTest.java | 2 - .../exoplayer2/testutil/ExtractorAsserts.java | 57 +++---------------- 6 files changed, 9 insertions(+), 81 deletions(-) diff --git a/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacExtractorTest.java b/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacExtractorTest.java index e203849bb9..dd7231c51e 100644 --- a/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacExtractorTest.java +++ b/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacExtractorTest.java @@ -17,7 +17,6 @@ package com.google.android.exoplayer2.ext.flac; import static org.junit.Assert.fail; -import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.testutil.ExtractorAsserts; import org.junit.Before; @@ -40,7 +39,6 @@ public class FlacExtractorTest { ExtractorAsserts.assertBehavior( FlacExtractor::new, /* file= */ "flac/bear.flac", - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_raw"); } @@ -49,7 +47,6 @@ public class FlacExtractorTest { ExtractorAsserts.assertBehavior( FlacExtractor::new, /* file= */ "flac/bear_with_id3.flac", - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_with_id3_enabled_raw"); } @@ -58,7 +55,6 @@ public class FlacExtractorTest { ExtractorAsserts.assertBehavior( () -> new FlacExtractor(FlacExtractor.FLAG_DISABLE_ID3_METADATA), /* file= */ "flac/bear_with_id3.flac", - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_with_id3_disabled_raw"); } @@ -67,7 +63,6 @@ public class FlacExtractorTest { ExtractorAsserts.assertBehavior( FlacExtractor::new, /* file= */ "flac/bear_no_seek_table_no_num_samples.flac", - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_no_seek_table_no_num_samples_raw"); } @@ -76,7 +71,6 @@ public class FlacExtractorTest { ExtractorAsserts.assertBehavior( FlacExtractor::new, /* file= */ "flac/bear_with_vorbis_comments.flac", - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_with_vorbis_comments_raw"); } @@ -85,7 +79,6 @@ public class FlacExtractorTest { ExtractorAsserts.assertBehavior( FlacExtractor::new, /* file= */ "flac/bear_with_picture.flac", - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_with_picture_raw"); } @@ -94,7 +87,6 @@ public class FlacExtractorTest { ExtractorAsserts.assertBehavior( FlacExtractor::new, /* file= */ "flac/bear_one_metadata_block.flac", - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_one_metadata_block_raw"); } @@ -103,7 +95,6 @@ public class FlacExtractorTest { ExtractorAsserts.assertBehavior( FlacExtractor::new, /* file= */ "flac/bear_no_min_max_frame_size.flac", - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_no_min_max_frame_size_raw"); } @@ -112,7 +103,6 @@ public class FlacExtractorTest { ExtractorAsserts.assertBehavior( FlacExtractor::new, /* file= */ "flac/bear_no_num_samples.flac", - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_no_num_samples_raw"); } @@ -121,7 +111,6 @@ public class FlacExtractorTest { ExtractorAsserts.assertBehavior( FlacExtractor::new, /* file= */ "flac/bear_uncommon_sample_rate.flac", - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_uncommon_sample_rate_raw"); } } diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/flac/FlacExtractorTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/flac/FlacExtractorTest.java index b66ac969e1..a620ee2515 100644 --- a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/flac/FlacExtractorTest.java +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/flac/FlacExtractorTest.java @@ -15,7 +15,6 @@ */ package com.google.android.exoplayer2.extractor.flac; -import androidx.test.core.app.ApplicationProvider; import com.google.android.exoplayer2.testutil.ExtractorAsserts; import java.util.List; import org.junit.Test; @@ -42,7 +41,6 @@ public class FlacExtractorTest { FlacExtractor::new, /* file= */ "flac/bear.flac", assertionConfig, - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_flac"); } @@ -52,7 +50,6 @@ public class FlacExtractorTest { FlacExtractor::new, /* file= */ "flac/bear_with_id3.flac", assertionConfig, - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_with_id3_enabled_flac"); } @@ -62,7 +59,6 @@ public class FlacExtractorTest { () -> new FlacExtractor(FlacExtractor.FLAG_DISABLE_ID3_METADATA), /* file= */ "flac/bear_with_id3.flac", assertionConfig, - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_with_id3_disabled_flac"); } @@ -72,7 +68,6 @@ public class FlacExtractorTest { FlacExtractor::new, /* file= */ "flac/bear_no_seek_table_no_num_samples.flac", assertionConfig, - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_no_seek_table_no_num_samples_flac"); } @@ -82,7 +77,6 @@ public class FlacExtractorTest { FlacExtractor::new, /* file= */ "flac/bear_with_vorbis_comments.flac", assertionConfig, - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_with_vorbis_comments_flac"); } @@ -92,7 +86,6 @@ public class FlacExtractorTest { FlacExtractor::new, /* file= */ "flac/bear_with_picture.flac", assertionConfig, - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_with_picture_flac"); } @@ -102,7 +95,6 @@ public class FlacExtractorTest { FlacExtractor::new, /* file= */ "flac/bear_one_metadata_block.flac", assertionConfig, - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_one_metadata_block_flac"); } @@ -112,7 +104,6 @@ public class FlacExtractorTest { FlacExtractor::new, /* file= */ "flac/bear_no_min_max_frame_size.flac", assertionConfig, - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_no_min_max_frame_size_flac"); } @@ -122,7 +113,6 @@ public class FlacExtractorTest { FlacExtractor::new, /* file= */ "flac/bear_no_num_samples.flac", assertionConfig, - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_no_num_samples_flac"); } @@ -132,7 +122,6 @@ public class FlacExtractorTest { FlacExtractor::new, /* file= */ "flac/bear_uncommon_sample_rate.flac", assertionConfig, - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "flac/bear_uncommon_sample_rate_flac"); } } diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/mp3/Mp3ExtractorTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/mp3/Mp3ExtractorTest.java index f87c3a1fa9..611c8f7e39 100644 --- a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/mp3/Mp3ExtractorTest.java +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/mp3/Mp3ExtractorTest.java @@ -15,7 +15,6 @@ */ package com.google.android.exoplayer2.extractor.mp3; -import androidx.test.core.app.ApplicationProvider; import com.google.android.exoplayer2.testutil.ExtractorAsserts; import java.util.List; import org.junit.Test; @@ -67,7 +66,6 @@ public final class Mp3ExtractorTest { Mp3Extractor::new, /* file= */ "mp3/bear-id3.mp3", assertionConfig, - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "mp3/bear-id3-enabled"); } @@ -77,7 +75,6 @@ public final class Mp3ExtractorTest { () -> new Mp3Extractor(Mp3Extractor.FLAG_DISABLE_ID3_METADATA), /* file= */ "mp3/bear-id3.mp3", assertionConfig, - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "mp3/bear-id3-disabled"); } } diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/ts/TsExtractorTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/ts/TsExtractorTest.java index c64d659fa0..68ba0d4983 100644 --- a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/ts/TsExtractorTest.java +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/ts/TsExtractorTest.java @@ -132,11 +132,7 @@ public final class TsExtractorTest { @Test public void streamWithJunkData() throws Exception { - ExtractorAsserts.assertBehavior( - TsExtractor::new, - "ts/sample_with_junk", - assertionConfig, - ApplicationProvider.getApplicationContext()); + ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_with_junk", assertionConfig); } @Test diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/wav/WavExtractorTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/wav/WavExtractorTest.java index 401308eb4e..cbcc847b85 100644 --- a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/wav/WavExtractorTest.java +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/wav/WavExtractorTest.java @@ -15,7 +15,6 @@ */ package com.google.android.exoplayer2.extractor.wav; -import androidx.test.core.app.ApplicationProvider; import com.google.android.exoplayer2.testutil.ExtractorAsserts; import java.util.List; import org.junit.Test; @@ -45,7 +44,6 @@ public final class WavExtractorTest { WavExtractor::new, "wav/sample_with_trailing_bytes.wav", assertionConfig, - ApplicationProvider.getApplicationContext(), /* dumpFilesPrefix= */ "wav/sample.wav"); } diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/ExtractorAsserts.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/ExtractorAsserts.java index 5bde3bdcf2..7e3f80acae 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/ExtractorAsserts.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/ExtractorAsserts.java @@ -136,7 +136,7 @@ public final class ExtractorAsserts { * @throws IOException If reading from the input fails. */ public static void assertBehavior(ExtractorFactory factory, String file) throws IOException { - assertBehavior(factory, file, ApplicationProvider.getApplicationContext()); + assertBehavior(factory, file, file); } /** @@ -152,39 +152,17 @@ public final class ExtractorAsserts { * @param factory An {@link ExtractorFactory} which creates instances of the {@link Extractor} * class which is to be tested. * @param file The path to the input sample. - * @param context To be used to load the sample file. - * @throws IOException If reading from the input fails. - */ - public static void assertBehavior(ExtractorFactory factory, String file, Context context) - throws IOException { - assertBehavior(factory, file, context, file); - } - - /** - * Asserts that an extractor behaves correctly given valid input data: - * - * - * - * @param factory An {@link ExtractorFactory} which creates instances of the {@link Extractor} - * class which is to be tested. - * @param file The path to the input sample. - * @param context To be used to load the sample file. * @param dumpFilesPrefix The dump files prefix appended to the dump files path. * @throws IOException If reading from the input fails. */ - public static void assertBehavior( - ExtractorFactory factory, String file, Context context, String dumpFilesPrefix) + public static void assertBehavior(ExtractorFactory factory, String file, String dumpFilesPrefix) throws IOException { // Check behavior prior to initialization. Extractor extractor = factory.create(); extractor.seek(0, 0); extractor.release(); // Assert output. + Context context = ApplicationProvider.getApplicationContext(); byte[] fileData = TestUtil.getByteArray(context, file); assertOutput(factory, dumpFilesPrefix, fileData, context); } @@ -204,26 +182,7 @@ public final class ExtractorAsserts { */ public static void assertBehavior(ExtractorFactory factory, String file, Config config) throws IOException { - assertBehavior(factory, file, config, ApplicationProvider.getApplicationContext()); - } - - /** - * Asserts that an extractor consumes valid input data successfully successfully under the - * conditions specified by {@code config}. - * - *

The output of the extractor is compared against prerecorded dump files whose names are - * derived from the {@code file} parameter. - * - * @param factory An {@link ExtractorFactory} which creates instances of the {@link Extractor} - * class which is to be tested. - * @param file The path to the input sample. - * @param config Details on the environment to simulate and behaviours to assert. - * @param context To be used to load the sample file. - * @throws IOException If reading from the input fails. - */ - public static void assertBehavior( - ExtractorFactory factory, String file, Config config, Context context) throws IOException { - assertBehavior(factory, file, config, context, file); + assertBehavior(factory, file, config, file); } /** @@ -236,18 +195,18 @@ public final class ExtractorAsserts { * class which is to be tested. * @param file The path to the input sample. * @param config Details on the environment to simulate and behaviours to assert. - * @param context To be used to load the sample file. * @param dumpFilesPrefix The dump files prefix prepended to the dump files path. * @throws IOException If reading from the input fails. */ public static void assertBehavior( - ExtractorFactory factory, String file, Config config, Context context, String dumpFilesPrefix) + ExtractorFactory factory, String file, Config config, String dumpFilesPrefix) throws IOException { // Check behavior prior to initialization. Extractor extractor = factory.create(); extractor.seek(0, 0); extractor.release(); // Assert output. + Context context = ApplicationProvider.getApplicationContext(); byte[] fileData = TestUtil.getByteArray(context, file); assertOutput( factory.create(), @@ -273,7 +232,7 @@ public final class ExtractorAsserts { * @param context To be used to load the sample file. * @throws IOException If reading from the input fails. */ - public static void assertOutput( + private static void assertOutput( ExtractorFactory factory, String dumpFilesPrefix, byte[] data, Context context) throws IOException { assertOutput(factory.create(), dumpFilesPrefix, data, context, true, false, false, false); @@ -303,7 +262,7 @@ public final class ExtractorAsserts { * @return The {@link FakeExtractorOutput} used in the test. * @throws IOException If reading from the input fails. */ - public static FakeExtractorOutput assertOutput( + private static FakeExtractorOutput assertOutput( Extractor extractor, String dumpFilesPrefix, byte[] data,