@Test
public void testAtomicTimelineWindowOrder() throws IOException {

  // Release default test runner with non-atomic media source and replace with new test runner.
  testRunner.release();
  ConcatenatingMediaSource mediaSource =
      new ConcatenatingMediaSource(/* isAtomic= */ true, new FakeShuffleOrder(0));
  testRunner = new MediaSourceTestRunner(mediaSource, null);
  mediaSource.addMediaSources(Arrays.asList(createMediaSources(3)));
  Timeline timeline = testRunner.prepareSource();
  TimelineAsserts.assertWindowTags(timeline, 111, 222, 333);
  TimelineAsserts.assertPeriodCounts(timeline, 1, 2, 3);
  TimelineAsserts.assertPreviousWindowIndices(
      timeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */ false, C.INDEX_UNSET, 0, 1);
  TimelineAsserts.assertPreviousWindowIndices(
      timeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */ true, C.INDEX_UNSET, 0, 1);
  TimelineAsserts.assertPreviousWindowIndices(
      timeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */ false, 2, 0, 1);
  TimelineAsserts.assertPreviousWindowIndices(
      timeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */ true, 2, 0, 1);
  TimelineAsserts.assertPreviousWindowIndices(
      timeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */ false, 2, 0, 1);
  TimelineAsserts.assertPreviousWindowIndices(
      timeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */ true, 2, 0, 1);
  TimelineAsserts.assertNextWindowIndices(
      timeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */ false, 1, 2, C.INDEX_UNSET);
  TimelineAsserts.assertNextWindowIndices(
      timeline, Player.REPEAT_MODE_OFF, /* shuffleModeEnabled= */ true, 1, 2, C.INDEX_UNSET);
  TimelineAsserts.assertNextWindowIndices(
      timeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */ false, 1, 2, 0);
  TimelineAsserts.assertNextWindowIndices(
      timeline, Player.REPEAT_MODE_ONE, /* shuffleModeEnabled= */ true, 1, 2, 0);
  TimelineAsserts.assertNextWindowIndices(
      timeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */ false, 1, 2, 0);
  TimelineAsserts.assertNextWindowIndices(
      timeline, Player.REPEAT_MODE_ALL, /* shuffleModeEnabled= */ true, 1, 2, 0);
  assertThat(timeline.getFirstWindowIndex(/* shuffleModeEnabled= */ false)).isEqualTo(0);
  assertThat(timeline.getFirstWindowIndex(/* shuffleModeEnabled= */ true)).isEqualTo(0);
  assertThat(timeline.getLastWindowIndex(/* shuffleModeEnabled= */ false)).isEqualTo(2);
  assertThat(timeline.getLastWindowIndex(/* shuffleModeEnabled= */ true)).isEqualTo(2);
}