Commit 5144b740 by samrobinson Committed by Ian Baker

Remove the need for a test runner TransformationResult.

PiperOrigin-RevId: 425882755
parent 032df64f
...@@ -22,6 +22,9 @@ import androidx.annotation.Nullable; ...@@ -22,6 +22,9 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.robolectric.RobolectricUtil; import com.google.android.exoplayer2.robolectric.RobolectricUtil;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.checkerframework.checker.nullness.compatqual.NullableType;
/** Helper class to run a {@link Transformer} test. */ /** Helper class to run a {@link Transformer} test. */
public final class TransformerTestRunner { public final class TransformerTestRunner {
...@@ -68,28 +71,27 @@ public final class TransformerTestRunner { ...@@ -68,28 +71,27 @@ public final class TransformerTestRunner {
@Nullable @Nullable
private static TransformationException runUntilListenerCalled(Transformer transformer) private static TransformationException runUntilListenerCalled(Transformer transformer)
throws TimeoutException { throws TimeoutException {
TransformationResult transformationResult = new TransformationResult(); AtomicBoolean transformationCompleted = new AtomicBoolean();
AtomicReference<@NullableType TransformationException> transformationException =
new AtomicReference<>();
transformer.addListener( transformer.addListener(
new Transformer.Listener() { new Transformer.Listener() {
@Override @Override
public void onTransformationCompleted(MediaItem inputMediaItem) { public void onTransformationCompleted(MediaItem inputMediaItem) {
transformationResult.isCompleted = true; transformationCompleted.set(true);
} }
@Override @Override
public void onTransformationError( public void onTransformationError(
MediaItem inputMediaItem, TransformationException exception) { MediaItem inputMediaItem, TransformationException exception) {
transformationResult.exception = exception; transformationException.set(exception);
} }
}); });
runLooperUntil( runLooperUntil(
transformer.getApplicationLooper(), transformer.getApplicationLooper(),
() -> transformationResult.isCompleted || transformationResult.exception != null); () -> transformationCompleted.get() || transformationException.get() != null);
return transformationResult.exception;
}
private static class TransformationResult { return transformationException.get();
public boolean isCompleted;
@Nullable public TransformationException exception;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment