@Test
public void testGetCastTimelinePersistsDuration() {

  CastTimelineTracker tracker = new CastTimelineTracker();
  RemoteMediaClient remoteMediaClient =
      mockRemoteMediaClient(
          /* itemIds= */ new int[] {1, 2, 3, 4, 5},
          /* currentItemId= */ 2,
          /* currentDurationMs= */ DURATION_2_MS);
  TimelineAsserts.assertPeriodDurations(
      tracker.getCastTimeline(remoteMediaClient),
      C.TIME_UNSET,
      C.msToUs(DURATION_2_MS),
      C.TIME_UNSET,
      C.TIME_UNSET,
      C.TIME_UNSET);
  remoteMediaClient =
      mockRemoteMediaClient(
          /* itemIds= */ new int[] {1, 2, 3},
          /* currentItemId= */ 3,
          /* currentDurationMs= */ DURATION_3_MS);
  TimelineAsserts.assertPeriodDurations(
      tracker.getCastTimeline(remoteMediaClient),
      C.TIME_UNSET,
      C.msToUs(DURATION_2_MS),
      C.msToUs(DURATION_3_MS));
  remoteMediaClient =
      mockRemoteMediaClient(
          /* itemIds= */ new int[] {1, 3},
          /* currentItemId= */ 3,
          /* currentDurationMs= */ DURATION_3_MS);
  TimelineAsserts.assertPeriodDurations(
      tracker.getCastTimeline(remoteMediaClient), C.TIME_UNSET, C.msToUs(DURATION_3_MS));
  remoteMediaClient =
      mockRemoteMediaClient(
          /* itemIds= */ new int[] {1, 2, 3, 4, 5},
          /* currentItemId= */ 4,
          /* currentDurationMs= */ DURATION_4_MS);
  TimelineAsserts.assertPeriodDurations(
      tracker.getCastTimeline(remoteMediaClient),
      C.TIME_UNSET,
      C.TIME_UNSET,
      C.msToUs(DURATION_3_MS),
      C.msToUs(DURATION_4_MS),
      C.TIME_UNSET);
  remoteMediaClient =
      mockRemoteMediaClient(
          /* itemIds= */ new int[] {1, 2, 3, 4, 5},
          /* currentItemId= */ 5,
          /* currentDurationMs= */ DURATION_5_MS);
  TimelineAsserts.assertPeriodDurations(
      tracker.getCastTimeline(remoteMediaClient),
      C.TIME_UNSET,
      C.TIME_UNSET,
      C.msToUs(DURATION_3_MS),
      C.msToUs(DURATION_4_MS),
      C.msToUs(DURATION_5_MS));
}