@VisibleForTesting
  ExportResult<MusicContainerResource> exportPlaylists(
      TokensAndUrlAuthData authData, Optional<PaginationData> paginationData, UUID jobId)
      throws IOException, InvalidTokenException, PermissionDeniedException {
    Optional<String> paginationToken = Optional.empty();
    String pageTokenPrefix = "";
    if (paginationData.isPresent()) {
      String token = ((StringPaginationToken) paginationData.get()).getToken();
      Preconditions.checkArgument(
          token.startsWith(PLAYLIST_TOKEN_PREFIX), "Invalid pagination token %s", token);
      pageTokenPrefix = token.substring(0, getTokenPrefixLength(token));
      if (getTokenPrefixLength(token) < token.length()) {
        paginationToken = Optional.of(token.substring(getTokenPrefixLength(token)));
      }
    }

    PlaylistExportResponse playlistExportResponse =
        getOrCreateMusicHttpApi(authData).exportPlaylists(paginationToken);

    PaginationData nextPageData;
    String token = playlistExportResponse.getNextPageToken();
    List<MusicPlaylist> playlists = new ArrayList<>();
    GooglePlaylist[] googlePlaylists = playlistExportResponse.getPlaylists();
    ResultType resultType = ResultType.END;

    if (Strings.isNullOrEmpty(token)) {
      nextPageData =
          new StringPaginationToken(pageTokenPrefix.substring(PLAYLIST_TOKEN_PREFIX.length()));
    } else {
      nextPageData = new StringPaginationToken(pageTokenPrefix + token);
      resultType = ResultType.CONTINUE;
    }
    ContinuationData continuationData = new ContinuationData(nextPageData);

    if (googlePlaylists != null && googlePlaylists.length > 0) {
      for (GooglePlaylist googlePlaylist : googlePlaylists) {
        Instant createTime = googlePlaylist.getCreateTime() == null ? null
            : Instant.parse(googlePlaylist.getCreateTime());
        Instant updateTime = googlePlaylist.getUpdateTime() == null ? null
            : Instant.parse(googlePlaylist.getUpdateTime());
        MusicPlaylist musicPlaylist =
            new MusicPlaylist(
                googlePlaylist.getName().substring(GOOGLE_PLAYLIST_NAME_PREFIX.length()),
                googlePlaylist.getTitle(),
                googlePlaylist.getDescription(),
                createTime, updateTime);
        playlists.add(musicPlaylist);

        monitor.debug(
            () ->
                String.format(
                    "%s: Google Music exporting playlist: %s", jobId, musicPlaylist.getId()));

        // Add playlist id to continuation data
        continuationData.addContainerResource(new IdOnlyContainerResource(musicPlaylist.getId()));
      }
    }

    MusicContainerResource containerResource =
        new MusicContainerResource(playlists, null, null, null);
    return new ExportResult<>(resultType, containerResource, continuationData);
  }
@Test
  public void exportPlaylistSubsequentSet()
      throws IOException, InvalidTokenException, PermissionDeniedException {
    setUpSinglePlaylist(GOOGLE_PLAYLIST_NAME_PREFIX + "p1_id");
    when(playlistExportResponse.getNextPageToken()).thenReturn(null);

    StringPaginationToken inputPaginationToken =
        new StringPaginationToken(PLAYLIST_TOKEN_PREFIX + PLAYLIST_PAGE_TOKEN);

    // Run test
    ExportResult<MusicContainerResource> result =
        googleMusicExporter.exportPlaylists(null, Optional.of(inputPaginationToken), uuid);

    // Check results
    // Verify correct methods were called
    verify(musicHttpApi).exportPlaylists(Optional.of(PLAYLIST_PAGE_TOKEN));
    verify(playlistExportResponse).getPlaylists();

    // Check pagination token - should be absent
    ContinuationData continuationData = result.getContinuationData();
    StringPaginationToken paginationData =
        (StringPaginationToken) continuationData.getPaginationData();
    assertThat(paginationData.getToken()).isEmpty();
  }