@Test
public void testClear() throws Exception {

  DummyMainThread dummyMainThread = new DummyMainThread();
  final FakeMediaSource preparedChildSource = createFakeMediaSource();
  final FakeMediaSource unpreparedChildSource = new FakeMediaSource(/* timeline= */ null);
  dummyMainThread.runOnMainThread(
      () -> {
        mediaSource.addMediaSource(preparedChildSource);
        mediaSource.addMediaSource(unpreparedChildSource);
      });
  testRunner.prepareSource();
  final TimelineGrabber timelineGrabber = new TimelineGrabber(testRunner);
  dummyMainThread.runOnMainThread(() -> mediaSource.clear(new Handler(), timelineGrabber));
  Timeline timeline = timelineGrabber.assertTimelineChangeBlocking();
  assertThat(timeline.isEmpty()).isTrue();
  preparedChildSource.assertReleased();
  unpreparedChildSource.assertReleased();
}