Remove ExtractorAsserts overloads that take a Context

Also mark the two assertOutput methods private, to make the API surface
smaller.

PiperOrigin-RevId: 308228186
This commit is contained in:
ibaker 2020-04-24 11:46:09 +01:00 committed by Ian Baker
parent 1323dd63d5
commit 0e6b318138
6 changed files with 9 additions and 81 deletions

View File

@ -17,7 +17,6 @@ package com.google.android.exoplayer2.ext.flac;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.testutil.ExtractorAsserts; import com.google.android.exoplayer2.testutil.ExtractorAsserts;
import org.junit.Before; import org.junit.Before;
@ -40,7 +39,6 @@ public class FlacExtractorTest {
ExtractorAsserts.assertBehavior( ExtractorAsserts.assertBehavior(
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear.flac", /* file= */ "flac/bear.flac",
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_raw"); /* dumpFilesPrefix= */ "flac/bear_raw");
} }
@ -49,7 +47,6 @@ public class FlacExtractorTest {
ExtractorAsserts.assertBehavior( ExtractorAsserts.assertBehavior(
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_with_id3.flac", /* file= */ "flac/bear_with_id3.flac",
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_with_id3_enabled_raw"); /* dumpFilesPrefix= */ "flac/bear_with_id3_enabled_raw");
} }
@ -58,7 +55,6 @@ public class FlacExtractorTest {
ExtractorAsserts.assertBehavior( ExtractorAsserts.assertBehavior(
() -> new FlacExtractor(FlacExtractor.FLAG_DISABLE_ID3_METADATA), () -> new FlacExtractor(FlacExtractor.FLAG_DISABLE_ID3_METADATA),
/* file= */ "flac/bear_with_id3.flac", /* file= */ "flac/bear_with_id3.flac",
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_with_id3_disabled_raw"); /* dumpFilesPrefix= */ "flac/bear_with_id3_disabled_raw");
} }
@ -67,7 +63,6 @@ public class FlacExtractorTest {
ExtractorAsserts.assertBehavior( ExtractorAsserts.assertBehavior(
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_no_seek_table_no_num_samples.flac", /* file= */ "flac/bear_no_seek_table_no_num_samples.flac",
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_no_seek_table_no_num_samples_raw"); /* dumpFilesPrefix= */ "flac/bear_no_seek_table_no_num_samples_raw");
} }
@ -76,7 +71,6 @@ public class FlacExtractorTest {
ExtractorAsserts.assertBehavior( ExtractorAsserts.assertBehavior(
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_with_vorbis_comments.flac", /* file= */ "flac/bear_with_vorbis_comments.flac",
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_with_vorbis_comments_raw"); /* dumpFilesPrefix= */ "flac/bear_with_vorbis_comments_raw");
} }
@ -85,7 +79,6 @@ public class FlacExtractorTest {
ExtractorAsserts.assertBehavior( ExtractorAsserts.assertBehavior(
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_with_picture.flac", /* file= */ "flac/bear_with_picture.flac",
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_with_picture_raw"); /* dumpFilesPrefix= */ "flac/bear_with_picture_raw");
} }
@ -94,7 +87,6 @@ public class FlacExtractorTest {
ExtractorAsserts.assertBehavior( ExtractorAsserts.assertBehavior(
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_one_metadata_block.flac", /* file= */ "flac/bear_one_metadata_block.flac",
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_one_metadata_block_raw"); /* dumpFilesPrefix= */ "flac/bear_one_metadata_block_raw");
} }
@ -103,7 +95,6 @@ public class FlacExtractorTest {
ExtractorAsserts.assertBehavior( ExtractorAsserts.assertBehavior(
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_no_min_max_frame_size.flac", /* file= */ "flac/bear_no_min_max_frame_size.flac",
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_no_min_max_frame_size_raw"); /* dumpFilesPrefix= */ "flac/bear_no_min_max_frame_size_raw");
} }
@ -112,7 +103,6 @@ public class FlacExtractorTest {
ExtractorAsserts.assertBehavior( ExtractorAsserts.assertBehavior(
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_no_num_samples.flac", /* file= */ "flac/bear_no_num_samples.flac",
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_no_num_samples_raw"); /* dumpFilesPrefix= */ "flac/bear_no_num_samples_raw");
} }
@ -121,7 +111,6 @@ public class FlacExtractorTest {
ExtractorAsserts.assertBehavior( ExtractorAsserts.assertBehavior(
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_uncommon_sample_rate.flac", /* file= */ "flac/bear_uncommon_sample_rate.flac",
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_uncommon_sample_rate_raw"); /* dumpFilesPrefix= */ "flac/bear_uncommon_sample_rate_raw");
} }
} }

View File

@ -15,7 +15,6 @@
*/ */
package com.google.android.exoplayer2.extractor.flac; package com.google.android.exoplayer2.extractor.flac;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.exoplayer2.testutil.ExtractorAsserts; import com.google.android.exoplayer2.testutil.ExtractorAsserts;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.Test;
@ -42,7 +41,6 @@ public class FlacExtractorTest {
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear.flac", /* file= */ "flac/bear.flac",
assertionConfig, assertionConfig,
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_flac"); /* dumpFilesPrefix= */ "flac/bear_flac");
} }
@ -52,7 +50,6 @@ public class FlacExtractorTest {
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_with_id3.flac", /* file= */ "flac/bear_with_id3.flac",
assertionConfig, assertionConfig,
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_with_id3_enabled_flac"); /* dumpFilesPrefix= */ "flac/bear_with_id3_enabled_flac");
} }
@ -62,7 +59,6 @@ public class FlacExtractorTest {
() -> new FlacExtractor(FlacExtractor.FLAG_DISABLE_ID3_METADATA), () -> new FlacExtractor(FlacExtractor.FLAG_DISABLE_ID3_METADATA),
/* file= */ "flac/bear_with_id3.flac", /* file= */ "flac/bear_with_id3.flac",
assertionConfig, assertionConfig,
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_with_id3_disabled_flac"); /* dumpFilesPrefix= */ "flac/bear_with_id3_disabled_flac");
} }
@ -72,7 +68,6 @@ public class FlacExtractorTest {
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_no_seek_table_no_num_samples.flac", /* file= */ "flac/bear_no_seek_table_no_num_samples.flac",
assertionConfig, assertionConfig,
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_no_seek_table_no_num_samples_flac"); /* dumpFilesPrefix= */ "flac/bear_no_seek_table_no_num_samples_flac");
} }
@ -82,7 +77,6 @@ public class FlacExtractorTest {
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_with_vorbis_comments.flac", /* file= */ "flac/bear_with_vorbis_comments.flac",
assertionConfig, assertionConfig,
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_with_vorbis_comments_flac"); /* dumpFilesPrefix= */ "flac/bear_with_vorbis_comments_flac");
} }
@ -92,7 +86,6 @@ public class FlacExtractorTest {
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_with_picture.flac", /* file= */ "flac/bear_with_picture.flac",
assertionConfig, assertionConfig,
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_with_picture_flac"); /* dumpFilesPrefix= */ "flac/bear_with_picture_flac");
} }
@ -102,7 +95,6 @@ public class FlacExtractorTest {
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_one_metadata_block.flac", /* file= */ "flac/bear_one_metadata_block.flac",
assertionConfig, assertionConfig,
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_one_metadata_block_flac"); /* dumpFilesPrefix= */ "flac/bear_one_metadata_block_flac");
} }
@ -112,7 +104,6 @@ public class FlacExtractorTest {
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_no_min_max_frame_size.flac", /* file= */ "flac/bear_no_min_max_frame_size.flac",
assertionConfig, assertionConfig,
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_no_min_max_frame_size_flac"); /* dumpFilesPrefix= */ "flac/bear_no_min_max_frame_size_flac");
} }
@ -122,7 +113,6 @@ public class FlacExtractorTest {
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_no_num_samples.flac", /* file= */ "flac/bear_no_num_samples.flac",
assertionConfig, assertionConfig,
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_no_num_samples_flac"); /* dumpFilesPrefix= */ "flac/bear_no_num_samples_flac");
} }
@ -132,7 +122,6 @@ public class FlacExtractorTest {
FlacExtractor::new, FlacExtractor::new,
/* file= */ "flac/bear_uncommon_sample_rate.flac", /* file= */ "flac/bear_uncommon_sample_rate.flac",
assertionConfig, assertionConfig,
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "flac/bear_uncommon_sample_rate_flac"); /* dumpFilesPrefix= */ "flac/bear_uncommon_sample_rate_flac");
} }
} }

View File

@ -15,7 +15,6 @@
*/ */
package com.google.android.exoplayer2.extractor.mp3; package com.google.android.exoplayer2.extractor.mp3;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.exoplayer2.testutil.ExtractorAsserts; import com.google.android.exoplayer2.testutil.ExtractorAsserts;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.Test;
@ -67,7 +66,6 @@ public final class Mp3ExtractorTest {
Mp3Extractor::new, Mp3Extractor::new,
/* file= */ "mp3/bear-id3.mp3", /* file= */ "mp3/bear-id3.mp3",
assertionConfig, assertionConfig,
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "mp3/bear-id3-enabled"); /* dumpFilesPrefix= */ "mp3/bear-id3-enabled");
} }
@ -77,7 +75,6 @@ public final class Mp3ExtractorTest {
() -> new Mp3Extractor(Mp3Extractor.FLAG_DISABLE_ID3_METADATA), () -> new Mp3Extractor(Mp3Extractor.FLAG_DISABLE_ID3_METADATA),
/* file= */ "mp3/bear-id3.mp3", /* file= */ "mp3/bear-id3.mp3",
assertionConfig, assertionConfig,
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "mp3/bear-id3-disabled"); /* dumpFilesPrefix= */ "mp3/bear-id3-disabled");
} }
} }

View File

@ -132,11 +132,7 @@ public final class TsExtractorTest {
@Test @Test
public void streamWithJunkData() throws Exception { public void streamWithJunkData() throws Exception {
ExtractorAsserts.assertBehavior( ExtractorAsserts.assertBehavior(TsExtractor::new, "ts/sample_with_junk", assertionConfig);
TsExtractor::new,
"ts/sample_with_junk",
assertionConfig,
ApplicationProvider.getApplicationContext());
} }
@Test @Test

View File

@ -15,7 +15,6 @@
*/ */
package com.google.android.exoplayer2.extractor.wav; package com.google.android.exoplayer2.extractor.wav;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.exoplayer2.testutil.ExtractorAsserts; import com.google.android.exoplayer2.testutil.ExtractorAsserts;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.Test;
@ -45,7 +44,6 @@ public final class WavExtractorTest {
WavExtractor::new, WavExtractor::new,
"wav/sample_with_trailing_bytes.wav", "wav/sample_with_trailing_bytes.wav",
assertionConfig, assertionConfig,
ApplicationProvider.getApplicationContext(),
/* dumpFilesPrefix= */ "wav/sample.wav"); /* dumpFilesPrefix= */ "wav/sample.wav");
} }

View File

@ -136,7 +136,7 @@ public final class ExtractorAsserts {
* @throws IOException If reading from the input fails. * @throws IOException If reading from the input fails.
*/ */
public static void assertBehavior(ExtractorFactory factory, String file) throws IOException { 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} * @param factory An {@link ExtractorFactory} which creates instances of the {@link Extractor}
* class which is to be tested. * class which is to be tested.
* @param file The path to the input sample. * @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:
*
* <ul>
* <li>Calls {@link Extractor#seek(long, long)} and {@link Extractor#release()} without calling
* {@link Extractor#init(ExtractorOutput)} to check these calls do not fail.
* <li>Calls {@link #assertOutput(Extractor, String, byte[], Context, boolean, boolean, boolean,
* boolean)} with all possible combinations of "simulate" parameters.
* </ul>
*
* @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. * @param dumpFilesPrefix The dump files prefix appended to the dump files path.
* @throws IOException If reading from the input fails. * @throws IOException If reading from the input fails.
*/ */
public static void assertBehavior( public static void assertBehavior(ExtractorFactory factory, String file, String dumpFilesPrefix)
ExtractorFactory factory, String file, Context context, String dumpFilesPrefix)
throws IOException { throws IOException {
// Check behavior prior to initialization. // Check behavior prior to initialization.
Extractor extractor = factory.create(); Extractor extractor = factory.create();
extractor.seek(0, 0); extractor.seek(0, 0);
extractor.release(); extractor.release();
// Assert output. // Assert output.
Context context = ApplicationProvider.getApplicationContext();
byte[] fileData = TestUtil.getByteArray(context, file); byte[] fileData = TestUtil.getByteArray(context, file);
assertOutput(factory, dumpFilesPrefix, fileData, context); assertOutput(factory, dumpFilesPrefix, fileData, context);
} }
@ -204,26 +182,7 @@ public final class ExtractorAsserts {
*/ */
public static void assertBehavior(ExtractorFactory factory, String file, Config config) public static void assertBehavior(ExtractorFactory factory, String file, Config config)
throws IOException { throws IOException {
assertBehavior(factory, file, config, ApplicationProvider.getApplicationContext()); assertBehavior(factory, file, config, file);
}
/**
* Asserts that an extractor consumes valid input data successfully successfully under the
* conditions specified by {@code config}.
*
* <p>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);
} }
/** /**
@ -236,18 +195,18 @@ public final class ExtractorAsserts {
* class which is to be tested. * class which is to be tested.
* @param file The path to the input sample. * @param file The path to the input sample.
* @param config Details on the environment to simulate and behaviours to assert. * @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. * @param dumpFilesPrefix The dump files prefix prepended to the dump files path.
* @throws IOException If reading from the input fails. * @throws IOException If reading from the input fails.
*/ */
public static void assertBehavior( public static void assertBehavior(
ExtractorFactory factory, String file, Config config, Context context, String dumpFilesPrefix) ExtractorFactory factory, String file, Config config, String dumpFilesPrefix)
throws IOException { throws IOException {
// Check behavior prior to initialization. // Check behavior prior to initialization.
Extractor extractor = factory.create(); Extractor extractor = factory.create();
extractor.seek(0, 0); extractor.seek(0, 0);
extractor.release(); extractor.release();
// Assert output. // Assert output.
Context context = ApplicationProvider.getApplicationContext();
byte[] fileData = TestUtil.getByteArray(context, file); byte[] fileData = TestUtil.getByteArray(context, file);
assertOutput( assertOutput(
factory.create(), factory.create(),
@ -273,7 +232,7 @@ public final class ExtractorAsserts {
* @param context To be used to load the sample file. * @param context To be used to load the sample file.
* @throws IOException If reading from the input fails. * @throws IOException If reading from the input fails.
*/ */
public static void assertOutput( private static void assertOutput(
ExtractorFactory factory, String dumpFilesPrefix, byte[] data, Context context) ExtractorFactory factory, String dumpFilesPrefix, byte[] data, Context context)
throws IOException { throws IOException {
assertOutput(factory.create(), dumpFilesPrefix, data, context, true, false, false, false); 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. * @return The {@link FakeExtractorOutput} used in the test.
* @throws IOException If reading from the input fails. * @throws IOException If reading from the input fails.
*/ */
public static FakeExtractorOutput assertOutput( private static FakeExtractorOutput assertOutput(
Extractor extractor, Extractor extractor,
String dumpFilesPrefix, String dumpFilesPrefix,
byte[] data, byte[] data,