Remove the need for a test runner TransformationResult.

PiperOrigin-RevId: 425882755
This commit is contained in:
samrobinson 2022-02-02 15:48:38 +00:00 committed by Ian Baker
parent daa45a16bd
commit 134c33ba47

View File

@ -22,6 +22,9 @@ import androidx.annotation.Nullable;
import androidx.media3.common.MediaItem; import androidx.media3.common.MediaItem;
import androidx.media3.test.utils.robolectric.RobolectricUtil; import androidx.media3.test.utils.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 {
@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;
} }
} }