@Test public void stop_withImapFolderPusherThrowing_shouldNotThrow() throws Exception { List<String> folderNames = Collections.singletonList("Archive"); imapPusher.start(folderNames); ImapFolderPusher imapFolderPusher = imapPusher.getImapFolderPushers().get(0); doThrow(RuntimeException.class).when(imapFolderPusher).stop(); imapPusher.stop(); }
@Test public void start_calledAfterStart_shouldStopFirstImapFolderPusher() throws Exception { imapPusher.start(Collections.singletonList("Drafts")); imapPusher.start(Collections.singletonList("INBOX")); ImapFolderPusher draftsPusher = imapPusher.getImapFolderPushers().get(0); verify(draftsPusher).stop(); }
@Test public void stop_afterStartWithSingleFolderName_shouldStopImapFolderPusher() throws Exception { List<String> folderNames = Collections.singletonList("Archive"); imapPusher.start(folderNames); imapPusher.stop(); List<ImapFolderPusher> imapFolderPushers = imapPusher.getImapFolderPushers(); assertEquals(1, imapFolderPushers.size()); ImapFolderPusher imapFolderPusher = imapFolderPushers.get(0); verify(imapFolderPusher).stop(); }
@Override public void stop() { if (K9MailLib.isDebug()) { Timber.i("Requested stop of IMAP pusher"); } synchronized (folderPushers) { for (ImapFolderPusher folderPusher : folderPushers) { try { if (K9MailLib.isDebug()) { Timber.i("Requesting stop of IMAP folderPusher %s", folderPusher.getServerId()); } folderPusher.stop(); } catch (Exception e) { Timber.e(e, "Got exception while stopping %s", folderPusher.getServerId()); } } folderPushers.clear(); } }