MailUtils { public static void setDeletedQuietly(MimeMessage message) { try { message.setFlag(Flags.Flag.DELETED, true); } catch (MessagingException e) { LOG.warn("Exception ", e); } } 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 canSetDeletedQuietlyOnException() throws MessagingException { MimeMessage mockMimeMsg = mock(MimeMessage.class); doThrowMessagingException().when(mockMimeMsg).setFlag(Flags.Flag.DELETED, true); MailUtils.setDeletedQuietly(mockMimeMsg); }