@VisibleForTesting
  ExportResult<MusicContainerResource> exportPlaylistItems(
      TokensAndUrlAuthData authData,
      IdOnlyContainerResource playlistData,
      Optional<PaginationData> paginationData, UUID jobId)
      throws IOException, InvalidTokenException, PermissionDeniedException, ParseException {
    String playlistId = playlistData.getId();
    Optional<String> paginationToken =
        paginationData.map((PaginationData value) -> ((StringPaginationToken) value).getToken());

    PlaylistItemExportResponse playlistItemExportResponse =
        getOrCreateMusicHttpApi(authData).exportPlaylistItems(playlistId, paginationToken);

    PaginationData nextPageData = null;
    if (!Strings.isNullOrEmpty(playlistItemExportResponse.getNextPageToken())) {
      nextPageData = new StringPaginationToken(playlistItemExportResponse.getNextPageToken());
    }
    ContinuationData continuationData = new ContinuationData(nextPageData);

    MusicContainerResource containerResource = null;
    GooglePlaylistItem[] googlePlaylistItems = playlistItemExportResponse.getPlaylistItems();
    List<MusicPlaylistItem> playlistItems = new ArrayList<>();
    if (googlePlaylistItems != null && googlePlaylistItems.length > 0) {
      for (GooglePlaylistItem googlePlaylistItem : googlePlaylistItems) {
        playlistItems.add(convertPlaylistItem(playlistId, googlePlaylistItem));
        monitor.debug(
            () ->
                String.format(
                    "%s: Google Music exporting playlist item in %s : [track title: %s, track isrc: %s]",
                    jobId, playlistId,
                    googlePlaylistItem.getTrack().getTitle(),
                    googlePlaylistItem.getTrack().getIsrc()));
      }
      containerResource = new MusicContainerResource(null, playlistItems, null, null);
    }

    return new ExportResult<>(ResultType.CONTINUE, containerResource, continuationData);
  }
@Test
  public void exportPlaylistItemFirstSet()
      throws IOException, InvalidTokenException, PermissionDeniedException, ParseException {
    GooglePlaylistItem playlistItem = setUpSinglePlaylistItem("t1_isrc", "r1_icpn");
    when(playlistItemExportResponse.getPlaylistItems())
        .thenReturn(new GooglePlaylistItem[]{playlistItem});
    when(playlistItemExportResponse.getNextPageToken()).thenReturn(PLAYLIST_ITEM_TOKEN);

    IdOnlyContainerResource idOnlyContainerResource = new IdOnlyContainerResource("p1_id");

    ExportResult<MusicContainerResource> result =
        googleMusicExporter.exportPlaylistItems(null, idOnlyContainerResource, Optional.empty(),
            uuid);

    // Check results
    // Verify correct methods were called
    verify(musicHttpApi).exportPlaylistItems("p1_id", Optional.empty());
    verify(playlistItemExportResponse).getPlaylistItems();

    // Check pagination
    ContinuationData continuationData = result.getContinuationData();
    StringPaginationToken paginationToken =
        (StringPaginationToken) continuationData.getPaginationData();
    assertThat(paginationToken.getToken()).isEqualTo(PLAYLIST_ITEM_TOKEN);

    // Check playlist field of container (should be empty)
    Collection<MusicPlaylist> actualPlaylists = result.getExportedData().getPlaylists();
    assertThat(actualPlaylists).isEmpty();

    // Check playlistItems field of container
    List<MusicPlaylistItem> actualPlaylistItems = result.getExportedData().getPlaylistItems();
    assertThat(
        actualPlaylistItems.stream()
            .map(MusicPlaylistItem::getPlaylistId)
            .collect(Collectors.toList()))
        .containsExactly("p1_id"); // for download
    assertThat(
        actualPlaylistItems.stream()
            .map(MusicPlaylistItem::getTrack)
            .collect(Collectors.toList()))
        .containsExactly(
            new MusicRecording("t1_isrc", null, 0L, new MusicRelease("r1_icpn", null, null), null,
                true));
  }