Fix test which is relying on wrong Robolectric behavior.
Robolectric calls messages posted to the main thread immediately inline. This will change in the upcoming release and will break tests implicitly relying on that behavior. Update ConcatenatingMediaSourceTest to actually wait for the posted message. PiperOrigin-RevId: 242631531
This commit is contained in:
parent
18dcad9b8d
commit
14d40b0faf
@ -18,7 +18,6 @@ package com.google.android.exoplayer2.source;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.os.ConditionVariable;
|
||||
import android.os.Handler;
|
||||
@ -417,60 +416,101 @@ public final class ConcatenatingMediaSourceTest {
|
||||
|
||||
@Test
|
||||
public void testCustomCallbackBeforePreparationAddSingle() {
|
||||
Runnable runnable = mock(Runnable.class);
|
||||
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||
|
||||
mediaSource.addMediaSource(createFakeMediaSource(), new Handler(), runnable);
|
||||
verify(runnable).run();
|
||||
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||
dummyMainThread.runOnMainThread(
|
||||
() ->
|
||||
mediaSource.addMediaSource(
|
||||
createFakeMediaSource(), new Handler(), runnableInvoked::open));
|
||||
runnableInvoked.block(MediaSourceTestRunner.TIMEOUT_MS);
|
||||
dummyMainThread.release();
|
||||
|
||||
assertThat(runnableInvoked.block(0)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomCallbackBeforePreparationAddMultiple() {
|
||||
Runnable runnable = mock(Runnable.class);
|
||||
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||
|
||||
mediaSource.addMediaSources(
|
||||
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||
new Handler(),
|
||||
runnable);
|
||||
verify(runnable).run();
|
||||
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||
dummyMainThread.runOnMainThread(
|
||||
() ->
|
||||
mediaSource.addMediaSources(
|
||||
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||
new Handler(),
|
||||
runnableInvoked::open));
|
||||
runnableInvoked.block(MediaSourceTestRunner.TIMEOUT_MS);
|
||||
dummyMainThread.release();
|
||||
|
||||
assertThat(runnableInvoked.block(0)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomCallbackBeforePreparationAddSingleWithIndex() {
|
||||
Runnable runnable = mock(Runnable.class);
|
||||
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||
|
||||
mediaSource.addMediaSource(/* index */ 0, createFakeMediaSource(), new Handler(), runnable);
|
||||
verify(runnable).run();
|
||||
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||
dummyMainThread.runOnMainThread(
|
||||
() ->
|
||||
mediaSource.addMediaSource(
|
||||
/* index */ 0, createFakeMediaSource(), new Handler(), runnableInvoked::open));
|
||||
runnableInvoked.block(MediaSourceTestRunner.TIMEOUT_MS);
|
||||
dummyMainThread.release();
|
||||
|
||||
assertThat(runnableInvoked.block(0)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomCallbackBeforePreparationAddMultipleWithIndex() {
|
||||
Runnable runnable = mock(Runnable.class);
|
||||
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||
|
||||
mediaSource.addMediaSources(
|
||||
/* index */ 0,
|
||||
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||
new Handler(),
|
||||
runnable);
|
||||
verify(runnable).run();
|
||||
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||
dummyMainThread.runOnMainThread(
|
||||
() ->
|
||||
mediaSource.addMediaSources(
|
||||
/* index */ 0,
|
||||
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||
new Handler(),
|
||||
runnableInvoked::open));
|
||||
runnableInvoked.block(MediaSourceTestRunner.TIMEOUT_MS);
|
||||
dummyMainThread.release();
|
||||
|
||||
assertThat(runnableInvoked.block(0)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomCallbackBeforePreparationRemove() {
|
||||
Runnable runnable = mock(Runnable.class);
|
||||
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||
|
||||
mediaSource.addMediaSource(createFakeMediaSource());
|
||||
mediaSource.removeMediaSource(/* index */ 0, new Handler(), runnable);
|
||||
verify(runnable).run();
|
||||
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||
dummyMainThread.runOnMainThread(
|
||||
() -> {
|
||||
mediaSource.addMediaSource(createFakeMediaSource());
|
||||
mediaSource.removeMediaSource(/* index */ 0, new Handler(), runnableInvoked::open);
|
||||
});
|
||||
runnableInvoked.block(MediaSourceTestRunner.TIMEOUT_MS);
|
||||
dummyMainThread.release();
|
||||
|
||||
assertThat(runnableInvoked.block(0)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomCallbackBeforePreparationMove() {
|
||||
Runnable runnable = mock(Runnable.class);
|
||||
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||
|
||||
mediaSource.addMediaSources(
|
||||
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}));
|
||||
mediaSource.moveMediaSource(/* fromIndex */ 1, /* toIndex */ 0, new Handler(), runnable);
|
||||
verify(runnable).run();
|
||||
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||
dummyMainThread.runOnMainThread(
|
||||
() -> {
|
||||
mediaSource.addMediaSources(
|
||||
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}));
|
||||
mediaSource.moveMediaSource(
|
||||
/* fromIndex */ 1, /* toIndex */ 0, new Handler(), runnableInvoked::open);
|
||||
});
|
||||
runnableInvoked.block(MediaSourceTestRunner.TIMEOUT_MS);
|
||||
dummyMainThread.release();
|
||||
|
||||
assertThat(runnableInvoked.block(0)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -997,11 +1037,19 @@ public final class ConcatenatingMediaSourceTest {
|
||||
|
||||
@Test
|
||||
public void testCustomCallbackBeforePreparationSetShuffleOrder() throws Exception {
|
||||
Runnable runnable = mock(Runnable.class);
|
||||
mediaSource.setShuffleOrder(
|
||||
new ShuffleOrder.UnshuffledShuffleOrder(/* length= */ 0), new Handler(), runnable);
|
||||
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||
|
||||
verify(runnable).run();
|
||||
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||
dummyMainThread.runOnMainThread(
|
||||
() ->
|
||||
mediaSource.setShuffleOrder(
|
||||
new ShuffleOrder.UnshuffledShuffleOrder(/* length= */ 0),
|
||||
new Handler(),
|
||||
runnableInvoked::open));
|
||||
runnableInvoked.block(MediaSourceTestRunner.TIMEOUT_MS);
|
||||
dummyMainThread.release();
|
||||
|
||||
assertThat(runnableInvoked.block(0)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user