@Test
public void getNextMediaPeriodInfo_withMidrollAds_returnsCorrectMediaPeriodInfos() {

  setupTimeline(
      /* initialPositionUs= */ 0,
      /* adGroupTimesUs...= */ FIRST_AD_START_TIME_US,
      SECOND_AD_START_TIME_US);
  assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(
      /* startPositionUs= */ 0,
      /* endPositionUs= */ FIRST_AD_START_TIME_US,
      /* durationUs= */ FIRST_AD_START_TIME_US,
      /* isLast= */ false,
      /* nextAdGroupIndex= */ 0);
  // The next media period info should be null as we haven't loaded the ad yet.
  advance();
  assertNull(getNextMediaPeriodInfo());
  setAdGroupLoaded(/* adGroupIndex= */ 0);
  assertNextMediaPeriodInfoIsAd(
      /* adGroupIndex= */ 0, /* contentPositionUs= */ FIRST_AD_START_TIME_US);
  advance();
  assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(
      /* startPositionUs= */ FIRST_AD_START_TIME_US,
      /* endPositionUs= */ SECOND_AD_START_TIME_US,
      /* durationUs= */ SECOND_AD_START_TIME_US,
      /* isLast= */ false,
      /* nextAdGroupIndex= */ 1);
  advance();
  setAdGroupLoaded(/* adGroupIndex= */ 1);
  assertNextMediaPeriodInfoIsAd(
      /* adGroupIndex= */ 1, /* contentPositionUs= */ SECOND_AD_START_TIME_US);
  advance();
  assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(
      /* startPositionUs= */ SECOND_AD_START_TIME_US,
      /* endPositionUs= */ C.TIME_UNSET,
      /* durationUs= */ CONTENT_DURATION_US,
      /* isLast= */ true,
      /* nextAdGroupIndex= */ C.INDEX_UNSET);
}