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 com.google.common.truth.Truth.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
|
|
||||||
import android.os.ConditionVariable;
|
import android.os.ConditionVariable;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -417,60 +416,101 @@ public final class ConcatenatingMediaSourceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomCallbackBeforePreparationAddSingle() {
|
public void testCustomCallbackBeforePreparationAddSingle() {
|
||||||
Runnable runnable = mock(Runnable.class);
|
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||||
|
|
||||||
mediaSource.addMediaSource(createFakeMediaSource(), new Handler(), runnable);
|
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||||
verify(runnable).run();
|
dummyMainThread.runOnMainThread(
|
||||||
|
() ->
|
||||||
|
mediaSource.addMediaSource(
|
||||||
|
createFakeMediaSource(), new Handler(), runnableInvoked::open));
|
||||||
|
runnableInvoked.block(MediaSourceTestRunner.TIMEOUT_MS);
|
||||||
|
dummyMainThread.release();
|
||||||
|
|
||||||
|
assertThat(runnableInvoked.block(0)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomCallbackBeforePreparationAddMultiple() {
|
public void testCustomCallbackBeforePreparationAddMultiple() {
|
||||||
Runnable runnable = mock(Runnable.class);
|
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||||
|
|
||||||
|
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||||
|
dummyMainThread.runOnMainThread(
|
||||||
|
() ->
|
||||||
mediaSource.addMediaSources(
|
mediaSource.addMediaSources(
|
||||||
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||||
new Handler(),
|
new Handler(),
|
||||||
runnable);
|
runnableInvoked::open));
|
||||||
verify(runnable).run();
|
runnableInvoked.block(MediaSourceTestRunner.TIMEOUT_MS);
|
||||||
|
dummyMainThread.release();
|
||||||
|
|
||||||
|
assertThat(runnableInvoked.block(0)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomCallbackBeforePreparationAddSingleWithIndex() {
|
public void testCustomCallbackBeforePreparationAddSingleWithIndex() {
|
||||||
Runnable runnable = mock(Runnable.class);
|
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||||
|
|
||||||
mediaSource.addMediaSource(/* index */ 0, createFakeMediaSource(), new Handler(), runnable);
|
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||||
verify(runnable).run();
|
dummyMainThread.runOnMainThread(
|
||||||
|
() ->
|
||||||
|
mediaSource.addMediaSource(
|
||||||
|
/* index */ 0, createFakeMediaSource(), new Handler(), runnableInvoked::open));
|
||||||
|
runnableInvoked.block(MediaSourceTestRunner.TIMEOUT_MS);
|
||||||
|
dummyMainThread.release();
|
||||||
|
|
||||||
|
assertThat(runnableInvoked.block(0)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomCallbackBeforePreparationAddMultipleWithIndex() {
|
public void testCustomCallbackBeforePreparationAddMultipleWithIndex() {
|
||||||
Runnable runnable = mock(Runnable.class);
|
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||||
|
|
||||||
|
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||||
|
dummyMainThread.runOnMainThread(
|
||||||
|
() ->
|
||||||
mediaSource.addMediaSources(
|
mediaSource.addMediaSources(
|
||||||
/* index */ 0,
|
/* index */ 0,
|
||||||
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}),
|
||||||
new Handler(),
|
new Handler(),
|
||||||
runnable);
|
runnableInvoked::open));
|
||||||
verify(runnable).run();
|
runnableInvoked.block(MediaSourceTestRunner.TIMEOUT_MS);
|
||||||
|
dummyMainThread.release();
|
||||||
|
|
||||||
|
assertThat(runnableInvoked.block(0)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomCallbackBeforePreparationRemove() {
|
public void testCustomCallbackBeforePreparationRemove() {
|
||||||
Runnable runnable = mock(Runnable.class);
|
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||||
|
|
||||||
|
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||||
|
dummyMainThread.runOnMainThread(
|
||||||
|
() -> {
|
||||||
mediaSource.addMediaSource(createFakeMediaSource());
|
mediaSource.addMediaSource(createFakeMediaSource());
|
||||||
mediaSource.removeMediaSource(/* index */ 0, new Handler(), runnable);
|
mediaSource.removeMediaSource(/* index */ 0, new Handler(), runnableInvoked::open);
|
||||||
verify(runnable).run();
|
});
|
||||||
|
runnableInvoked.block(MediaSourceTestRunner.TIMEOUT_MS);
|
||||||
|
dummyMainThread.release();
|
||||||
|
|
||||||
|
assertThat(runnableInvoked.block(0)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomCallbackBeforePreparationMove() {
|
public void testCustomCallbackBeforePreparationMove() {
|
||||||
Runnable runnable = mock(Runnable.class);
|
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||||
|
|
||||||
|
DummyMainThread dummyMainThread = new DummyMainThread();
|
||||||
|
dummyMainThread.runOnMainThread(
|
||||||
|
() -> {
|
||||||
mediaSource.addMediaSources(
|
mediaSource.addMediaSources(
|
||||||
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}));
|
Arrays.asList(new MediaSource[] {createFakeMediaSource(), createFakeMediaSource()}));
|
||||||
mediaSource.moveMediaSource(/* fromIndex */ 1, /* toIndex */ 0, new Handler(), runnable);
|
mediaSource.moveMediaSource(
|
||||||
verify(runnable).run();
|
/* fromIndex */ 1, /* toIndex */ 0, new Handler(), runnableInvoked::open);
|
||||||
|
});
|
||||||
|
runnableInvoked.block(MediaSourceTestRunner.TIMEOUT_MS);
|
||||||
|
dummyMainThread.release();
|
||||||
|
|
||||||
|
assertThat(runnableInvoked.block(0)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -997,11 +1037,19 @@ public final class ConcatenatingMediaSourceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomCallbackBeforePreparationSetShuffleOrder() throws Exception {
|
public void testCustomCallbackBeforePreparationSetShuffleOrder() throws Exception {
|
||||||
Runnable runnable = mock(Runnable.class);
|
ConditionVariable runnableInvoked = new ConditionVariable();
|
||||||
mediaSource.setShuffleOrder(
|
|
||||||
new ShuffleOrder.UnshuffledShuffleOrder(/* length= */ 0), new Handler(), runnable);
|
|
||||||
|
|
||||||
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
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user