@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); }
inOrder.verify(get).setFormat("raw"); inOrder.verify(get).execute();
try { getResponse = gmail.users().messages().get(USER, listMessage.getId()).setFormat("raw").execute(); } catch (IOException e) { return new ExportResult<>(e);
/** * Retrieves the registration key among the unread emails * with {@code courseId} and {@code courseName} sent to the Gmail inbox. * * <p>After retrieving, marks the email as read. * * <p>If multiple emails of the same course are in the inbox, return the registration key presented in one of them. * * @return registration key (null if cannot be found). */ public String getRegistrationKeyFromUnreadEmails(String courseName, String courseId) throws IOException, MessagingException { List<Message> messageStubs = getListOfUnreadEmailOfUser(); for (Message messageStub : messageStubs) { Message message = service.users().messages().get(username, messageStub.getId()).setFormat("raw") .execute(); MimeMessage email = convertFromMessageToMimeMessage(message); if (isStudentCourseJoinRegistrationEmail(email, courseName, courseId)) { String body = getTextFromEmail(email); markMessageAsRead(messageStub); return getKey(body); } } return null; }