### Question:
GoogleMailExporter implements Exporter<TokensAndUrlAuthData, MailContainerResource> { @Override public ExportResult<MailContainerResource> export(UUID id, TokensAndUrlAuthData authData, Optional<ExportInformation> exportInformation) { Gmail gmail = getOrCreateGmail(authData); Messages.List request = null; try { request = gmail.users().messages().list(USER).setMaxResults(PAGE_SIZE); } catch (IOException e) { return new ExportResult<>(e); } if (exportInformation.isPresent() && exportInformation.get().getPaginationData() != null) { request.setPageToken( ((StringPaginationToken) exportInformation.get().getPaginationData()).getToken()); } ListMessagesResponse response = null; try { response = request.execute(); } catch (IOException e) { return new ExportResult<>(e); } List<MailMessageModel> results = new ArrayList<>(response.getMessages().size()); for (Message listMessage : response.getMessages()) { Message getResponse = null; try { getResponse = gmail.users().messages().get(USER, listMessage.getId()).setFormat("raw").execute(); } catch (IOException e) { return new ExportResult<>(e); } results.add(new MailMessageModel(getResponse.getRaw(), getResponse.getLabelIds())); } PaginationData newPage = null; ResultType resultType = ResultType.END; if (response.getNextPageToken() != null) { newPage = new StringPaginationToken(response.getNextPageToken()); resultType = ResultType.CONTINUE; } MailContainerResource mailContainerResource = new MailContainerResource(null, results); return new ExportResult<>(resultType, mailContainerResource, new ContinuationData(newPage)); } GoogleMailExporter(GoogleCredentialFactory credentialFactory); @VisibleForTesting  GoogleMailExporter(GoogleCredentialFactory credentialFactory, Gmail gmail); @Override ExportResult<MailContainerResource> export(UUID id,
      TokensAndUrlAuthData authData, Optional<ExportInformation> exportInformation);  }### Answer:
@Test public void exportMessagesFirstSet() throws IOException { setUpSingleMessageResponse(); messageListResponse.setNextPageToken(NEXT_TOKEN); ExportResult<MailContainerResource> result = googleMailExporter.export(JOB_ID, null, Optional.empty()); InOrder inOrder = Mockito.inOrder(messages, messageListRequest, get); inOrder.verify(messages).list(GoogleMailExporter.USER); inOrder.verify(messageListRequest).setMaxResults(GoogleMailExporter.PAGE_SIZE); verify(messageListRequest, never()).setPageToken(anyString()); inOrder.verify(messages).get(GoogleMailExporter.USER, MESSAGE_ID); inOrder.verify(get).setFormat("raw"); inOrder.verify(get).execute(); ContinuationData continuationData = (ContinuationData) result.getContinuationData(); StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData(); assertThat(paginationToken.getToken()).isEqualTo(NEXT_TOKEN); Collection<MailMessageModel> actualMail = result.getExportedData().getMessages(); assertThat(actualMail.stream().map(MailMessageModel::getRawString).collect(Collectors.toList())) .containsExactly(MESSAGE_RAW); assertThat( actualMail.stream().map(MailMessageModel::getContainerIds).collect(Collectors.toList())) .containsExactly(MESSAGE_LABELS); }
@Test public void exportMessagesSubsequentSet() throws IOException { setUpSingleMessageResponse(); PaginationData paginationData = new StringPaginationToken(NEXT_TOKEN); ExportInformation exportInformation = new ExportInformation(paginationData, null); messageListResponse.setNextPageToken(null); ExportResult<MailContainerResource> result = googleMailExporter.export(JOB_ID, null, Optional.of(exportInformation)); InOrder inOrder = Mockito.inOrder(messageListRequest); inOrder.verify(messageListRequest).setPageToken(NEXT_TOKEN); inOrder.verify(messageListRequest).execute(); ContinuationData continuationData = (ContinuationData) result.getContinuationData(); StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData(); assertThat(paginationToken).isNull(); }