@Test
public void
    updateQueuedPeriods_withDurationChangeBeforeReadingPeriod_doesntHandleChangeAndRemovesPeriodsAfterChangedPeriod() {

  setupTimeline(
      /* initialPositionUs= */ 0,
      /* adGroupTimesUs...= */ FIRST_AD_START_TIME_US,
      SECOND_AD_START_TIME_US);
  setAdGroupLoaded(/* adGroupIndex= */ 0);
  setAdGroupLoaded(/* adGroupIndex= */ 1);
  enqueueNext(); // Content before first ad.
  advancePlaying();
  enqueueNext(); // First ad.
  enqueueNext(); // Content between ads.
  enqueueNext(); // Second ad.
  advanceReading(); // Reading first ad.
  // Change position of first ad (= change duration of content before first ad).
  setupTimeline(
      /* initialPositionUs= */ 0,
      /* adGroupTimesUs...= */ FIRST_AD_START_TIME_US + 1,
      SECOND_AD_START_TIME_US);
  setAdGroupLoaded(/* adGroupIndex= */ 0);
  setAdGroupLoaded(/* adGroupIndex= */ 1);
  boolean changeHandled =
      mediaPeriodQueue.updateQueuedPeriods(
          /* rendererPositionUs= */ 0, /* maxRendererReadPositionUs= */ FIRST_AD_START_TIME_US);
  assertThat(changeHandled).isFalse();
  assertThat(getQueueLength()).isEqualTo(1);
}