MailUtils { public static void closeQuietly(Store store, Folder folder, boolean expunge) { if (folder != null) { try { folder.close(expunge); } catch (Exception e) { LOG.warn("Exception while closing java mail folder, expunge = " + expunge + ".", e); } } closeQuietly(store); } private  MailUtils(); static void closeQuietly(Store store, Folder folder, boolean expunge); static void closeQuietly(Store store); static Session getMailSession(Properties mailServerProps, String user, String pass); static void sendMessage(Address[] recipients, Session session, MimeMessage message); @SuppressWarnings("unchecked") static void logHeaders(final MimeMessage mimeMessage); static void setDeletedQuietly(MimeMessage message); static final String FOLDER_NAME_INBOX; static final boolean FOLDER_EXPUNGE_INBOX_TRUE; static final boolean FOLDER_EXPUNGE_INBOX_FALSE; }
@Test public void canCloseQuietlyOnStoreException() throws MessagingException { MailUtils.closeQuietly(getMockStore(true)); }
@Test public void canCloseBothQuietlyOnStoreException() throws MessagingException { MailUtils.closeQuietly(getMockStore(true), getMockFolder(false), MailUtils.FOLDER_EXPUNGE_INBOX_TRUE); }
@Test public void canCloseBothQuietlyOnFolderException() throws MessagingException { MailUtils.closeQuietly(getMockStore(false), getMockFolder(true), MailUtils.FOLDER_EXPUNGE_INBOX_TRUE); }