@Before public void setUp() throws Exception { executorService = Executors.newFixedThreadPool(1); mailboxPath = MailboxPath.forUser("tellier@linagora.com", MailboxConstants.INBOX); mailboxManager = mock(MailboxManager.class); messageManager = mock(MessageManager.class); imapSession = mock(ImapSession.class); mailbox = mock(Mailbox.class); when(mailboxManager.getMailbox(eq(mailboxPath), any(MailboxSession.class))) .thenReturn(messageManager); when(messageManager.getApplicableFlags(any(MailboxSession.class))) .thenReturn(new Flags()); when(messageManager.search(any(SearchQuery.class), any(MailboxSession.class))) .then(delayedSearchAnswer()); when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mock(MailboxSession.class)); when(mailbox.generateAssociatedPath()) .thenReturn(mailboxPath); }
@Before public void setUp() throws MailboxException { ImapSession imapSession = mock(ImapSession.class); when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)) .thenReturn(MAILBOX_SESSION); when(imapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED); MailboxManager mailboxManager = mock(MailboxManager.class); MessageManager messageManager = mock(MessageManager.class); when(mailboxManager.getDelimiter()).thenReturn(PATH_DELIMITER); when(mailboxManager.getMailbox(any(MailboxId.class), any(MailboxSession.class))) .thenReturn(messageManager); when(mailboxManager.getMailbox(any(MailboxPath.class), any(MailboxSession.class))) .thenReturn(messageManager); MessageResult messageResult = mock(MessageResult.class); when(messageResult.getMailboxId()).thenReturn(TestId.of(36)); when(messageResult.getUid()).thenReturn(MESSAGE_UID); when(messageManager.getApplicableFlags(any())) .thenReturn(new Flags()); when(messageManager.search(any(), any())) .thenReturn(ImmutableList.of(MESSAGE_UID).iterator()); when(messageManager.getMessages(any(), any(), any())) .thenReturn(new SingleMessageResultIterator(messageResult)); testee = new SelectedMailboxImpl(mailboxManager, imapSession, MAILBOX_PATH); }
public SelectedMailboxImpl(MailboxManager mailboxManager, ImapSession session, MailboxPath path) throws MailboxException { this.session = session; this.sessionId = ImapSessionUtils.getMailboxSession(session).getSessionId(); this.mailboxManager = mailboxManager; // Ignore events from our session setSilentFlagChanges(true); this.path = path; MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); uidMsnConverter = new UidMsnConverter(); mailboxManager.addListener(path, this, mailboxSession); MessageManager messageManager = mailboxManager.getMailbox(path, mailboxSession); applicableFlags = messageManager.getApplicableFlags(mailboxSession); uidMsnConverter.addAll(ImmutableList.copyOf( messageManager.search(new SearchQuery(SearchQuery.all()), mailboxSession))); }