From 2054b290892071e60cb8832bc9eecf8853cf18de Mon Sep 17 00:00:00 2001 From: samrobinson Date: Thu, 25 Nov 2021 11:58:12 +0000 Subject: [PATCH] Pull files from the device cache after a test concludes. PiperOrigin-RevId: 412251020 --- .../media3/transformer/AndroidTestUtil.java | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AndroidTestUtil.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AndroidTestUtil.java index a54e693d5c..b82a1e8f2e 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AndroidTestUtil.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AndroidTestUtil.java @@ -83,30 +83,26 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; Uri uri = Uri.parse(uriString); File externalCacheFile = createExternalCacheFile(context, /* filePrefix= */ testId); - try { - InstrumentationRegistry.getInstrumentation() - .runOnMainSync( - () -> { - try { - testTransformer.startTransformation( - MediaItem.fromUri(uri), externalCacheFile.getAbsolutePath()); - } catch (IOException e) { - exceptionReference.set(e); - } - }); + InstrumentationRegistry.getInstrumentation() + .runOnMainSync( + () -> { + try { + testTransformer.startTransformation( + MediaItem.fromUri(uri), externalCacheFile.getAbsolutePath()); + } catch (IOException e) { + exceptionReference.set(e); + } + }); - assertWithMessage("Transformer timed out after " + timeoutSeconds + " seconds.") - .that(countDownLatch.await(timeoutSeconds, SECONDS)) - .isTrue(); - @Nullable Exception exception = exceptionReference.get(); - if (exception != null) { - throw exception; - } - long outputSizeBytes = externalCacheFile.length(); - return new TransformationResult(outputSizeBytes); - } finally { - externalCacheFile.delete(); + assertWithMessage("Transformer timed out after " + timeoutSeconds + " seconds.") + .that(countDownLatch.await(timeoutSeconds, SECONDS)) + .isTrue(); + @Nullable Exception exception = exceptionReference.get(); + if (exception != null) { + throw exception; } + long outputSizeBytes = externalCacheFile.length(); + return new TransformationResult(outputSizeBytes); } private static File createExternalCacheFile(Context context, String filePrefix)