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.test.utils.robolectric.RobolectricUtil;
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. */
public final class TransformerTestRunner {
@ -68,28 +71,27 @@ public final class TransformerTestRunner {
@Nullable
private static TransformationException runUntilListenerCalled(Transformer transformer)
throws TimeoutException {
TransformationResult transformationResult = new TransformationResult();
AtomicBoolean transformationCompleted = new AtomicBoolean();
AtomicReference<@NullableType TransformationException> transformationException =
new AtomicReference<>();
transformer.addListener(
new Transformer.Listener() {
@Override
public void onTransformationCompleted(MediaItem inputMediaItem) {
transformationResult.isCompleted = true;
transformationCompleted.set(true);
}
@Override
public void onTransformationError(
MediaItem inputMediaItem, TransformationException exception) {
transformationResult.exception = exception;
transformationException.set(exception);
}
});
runLooperUntil(
transformer.getApplicationLooper(),
() -> transformationResult.isCompleted || transformationResult.exception != null);
return transformationResult.exception;
}
() -> transformationCompleted.get() || transformationException.get() != null);
private static class TransformationResult {
public boolean isCompleted;
@Nullable public TransformationException exception;
return transformationException.get();
}
}