@Test public void exportMessagesSubsequentSet() throws IOException { setUpSingleMessageResponse(); // Looking at subsequent page, with no page after it PaginationData paginationData = new StringPaginationToken(NEXT_TOKEN); ExportInformation exportInformation = new ExportInformation(paginationData, null); messageListResponse.setNextPageToken(null); // Run test ExportResult<MailContainerResource> result = googleMailExporter.export(JOB_ID, null, Optional.of(exportInformation)); // Check results // Verify correct calls were made (i.e., token was set before execution) InOrder inOrder = Mockito.inOrder(messageListRequest); inOrder.verify(messageListRequest).setPageToken(NEXT_TOKEN); inOrder.verify(messageListRequest).execute(); // Check pagination token (should be null) ContinuationData continuationData = (ContinuationData) result.getContinuationData(); StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData(); assertThat(paginationToken).isNull(); }
inOrder.verify(messageListRequest).setMaxResults(GoogleMailExporter.PAGE_SIZE); verify(messageListRequest, never()).setPageToken(Matchers.anyString());
/** * Lists the messages in the user's mailbox. * * Create a request for the method "messages.list". * * This request holds the parameters needed by the gmail server. After setting any optional * parameters, call the {@link List#execute()} method to invoke the remote operation. * * @param userId The user's email address. The special value me can be used to indicate the authenticated user. * [default: me] * @return the request */ public List list(java.lang.String userId) throws java.io.IOException { List result = new List(userId); initialize(result); return result; }
/** * Returns an empty list if there is no unread email of the user. */ private List<Message> getListOfUnreadEmailOfUser() throws IOException { List<Message> messageStubs = service.users().messages().list(username).setQ("is:UNREAD").execute().getMessages(); return messageStubs == null ? new ArrayList<>() : messageStubs; }
request = gmail.users().messages().list(USER).setMaxResults(PAGE_SIZE); } catch (IOException e) { return new ExportResult<>(e); request.setPageToken( ((StringPaginationToken) exportInformation.get().getPaginationData()).getToken()); response = request.execute(); } catch (IOException e) { return new ExportResult<>(e);
/** * Sets up a response with a single message */ private void setUpSingleMessageResponse() throws IOException { messageListResponse = new ListMessagesResponse() .setMessages(Collections.singletonList(INITIAL_MESSAGE)); when(messageListRequest.execute()).thenReturn(messageListResponse); when(get.execute()).thenReturn(FULL_MESSAGE); } }
@Before public void setup() throws IOException { googleMailExporter = new GoogleMailExporter(googleCredentialFactory, gmail); when(gmail.users()).thenReturn(users); when(users.messages()).thenReturn(messages); when(messages.list(Matchers.anyString())).thenReturn(messageListRequest); when(messageListRequest.setMaxResults(Matchers.anyLong())).thenReturn(messageListRequest); when(messages.get(Matchers.anyString(), Matchers.anyString())).thenReturn(get); when(get.setFormat(Matchers.anyString())).thenReturn(get); verifyZeroInteractions(googleCredentialFactory); }