Re-use test runner in each loop of RepeatedTranscodeTransformationTest

PiperOrigin-RevId: 438542239
This commit is contained in:
samrobinson 2022-03-31 13:23:44 +01:00 committed by Ian Baker
parent 839f342e55
commit d8e5e2de7a

View File

@ -40,7 +40,10 @@ public final class RepeatedTranscodeTransformationTest {
@Test
public void repeatedTranscode_givesConsistentLengthOutput() throws Exception {
Context context = ApplicationProvider.getApplicationContext();
Transformer transformer =
TransformerAndroidTestRunner transformerRunner =
new TransformerAndroidTestRunner.Builder(
context,
new Transformer.Builder(context)
.setTransformationRequest(
new TransformationRequest.Builder()
@ -48,15 +51,14 @@ public final class RepeatedTranscodeTransformationTest {
// Video MIME type is H264.
.setAudioMimeType(MimeTypes.AUDIO_AAC)
.build())
.build())
.build();
Set<Long> differentOutputSizesBytes = new HashSet<>();
for (int i = 0; i < TRANSCODE_COUNT; i++) {
// Use a long video in case an error occurs a while after the start of the video.
TransformationTestResult testResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(
transformerRunner.run(
/* testId= */ "repeatedTranscode_givesConsistentLengthOutput_" + i,
AndroidTestUtil.MP4_REMOTE_H264_MP3_URI_STRING);
differentOutputSizesBytes.add(checkNotNull(testResult.transformationResult.fileSizeBytes));
@ -71,7 +73,9 @@ public final class RepeatedTranscodeTransformationTest {
@Test
public void repeatedTranscodeNoAudio_givesConsistentLengthOutput() throws Exception {
Context context = ApplicationProvider.getApplicationContext();
Transformer transformer =
TransformerAndroidTestRunner transformerRunner =
new TransformerAndroidTestRunner.Builder(
context,
new Transformer.Builder(context)
.setRemoveAudio(true)
.setTransformationRequest(
@ -79,15 +83,14 @@ public final class RepeatedTranscodeTransformationTest {
// Video MIME type is H264.
.setRotationDegrees(45)
.build())
.build())
.build();
Set<Long> differentOutputSizesBytes = new HashSet<>();
for (int i = 0; i < TRANSCODE_COUNT; i++) {
// Use a long video in case an error occurs a while after the start of the video.
TransformationTestResult testResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(
transformerRunner.run(
/* testId= */ "repeatedTranscodeNoAudio_givesConsistentLengthOutput_" + i,
AndroidTestUtil.MP4_REMOTE_H264_MP3_URI_STRING);
differentOutputSizesBytes.add(checkNotNull(testResult.transformationResult.fileSizeBytes));
@ -102,20 +105,23 @@ public final class RepeatedTranscodeTransformationTest {
@Test
public void repeatedTranscodeNoVideo_givesConsistentLengthOutput() throws Exception {
Context context = ApplicationProvider.getApplicationContext();
Transformer transformer =
TransformerAndroidTestRunner transformerRunner =
new TransformerAndroidTestRunner.Builder(
context,
new Transformer.Builder(context)
.setRemoveVideo(true)
.setTransformationRequest(
new TransformationRequest.Builder().setAudioMimeType(MimeTypes.AUDIO_AAC).build())
new TransformationRequest.Builder()
.setAudioMimeType(MimeTypes.AUDIO_AAC)
.build())
.build())
.build();
Set<Long> differentOutputSizesBytes = new HashSet<>();
for (int i = 0; i < TRANSCODE_COUNT; i++) {
// Use a long video in case an error occurs a while after the start of the video.
TransformationTestResult testResult =
new TransformerAndroidTestRunner.Builder(context, transformer)
.build()
.run(
transformerRunner.run(
/* testId= */ "repeatedTranscodeNoVideo_givesConsistentLengthOutput_" + i,
AndroidTestUtil.MP4_REMOTE_H264_MP3_URI_STRING);
differentOutputSizesBytes.add(checkNotNull(testResult.transformationResult.fileSizeBytes));