@Test public void testGetNewMessages() throws MessagingException, IOException { Message[] messages = createMockMessages(15, 7); when(this.inboxMock.search(ArgumentMatchers.any(FlagTerm.class))).thenReturn(messages); assertEquals(Arrays.asList(messages), this.emailLogic.getNewMessages()); Mockito.doThrow(MessagingException.class).when(this.inboxMock).search(ArgumentMatchers.any(FlagTerm.class)); assertEquals(Collections.emptyList(), this.emailLogic.getNewMessages()); }
List<Message> getNewMessages() { try { List<Message> messages = Arrays .asList(this.mailSession.getInbox().search(new FlagTerm(new Flags(Flag.SEEN), false))); Collections.reverse(messages); return messages; } catch (MessagingException me) { this.logger.error("Searching for mails failed", me); return Collections.emptyList(); } }
EMailLogic { List<Message> getNewMessages() { try { List<Message> messages = Arrays .asList(this.mailSession.getInbox().search(new FlagTerm(new Flags(Flag.SEEN), false))); Collections.reverse(messages); return messages; } catch (MessagingException me) { this.logger.error("Searching for mails failed", me); return Collections.emptyList(); } } }
EMailLogic { List<Message> getNewMessages() { try { List<Message> messages = Arrays .asList(this.mailSession.getInbox().search(new FlagTerm(new Flags(Flag.SEEN), false))); Collections.reverse(messages); return messages; } catch (MessagingException me) { this.logger.error("Searching for mails failed", me); return Collections.emptyList(); } }  }
EMailLogic { List<Message> getNewMessages() { try { List<Message> messages = Arrays .asList(this.mailSession.getInbox().search(new FlagTerm(new Flags(Flag.SEEN), false))); Collections.reverse(messages); return messages; } catch (MessagingException me) { this.logger.error("Searching for mails failed", me); return Collections.emptyList(); } }  boolean hasNewMessages(boolean checkForImportant); int getNewMessageCount(boolean checkForImportant); String printMessages(int amount, boolean important); MessageDTO[] getMailsForREST(int amount); boolean connectToMailServer(EMailCredentials credentials); boolean isConnectedToMailServer(); void disconnectFromMailServer(); EMailCredentials getCredentials(); @PostConstruct void connectToMailServer(); }
EMailLogic { List<Message> getNewMessages() { try { List<Message> messages = Arrays .asList(this.mailSession.getInbox().search(new FlagTerm(new Flags(Flag.SEEN), false))); Collections.reverse(messages); return messages; } catch (MessagingException me) { this.logger.error("Searching for mails failed", me); return Collections.emptyList(); } }  boolean hasNewMessages(boolean checkForImportant); int getNewMessageCount(boolean checkForImportant); String printMessages(int amount, boolean important); MessageDTO[] getMailsForREST(int amount); boolean connectToMailServer(EMailCredentials credentials); boolean isConnectedToMailServer(); void disconnectFromMailServer(); EMailCredentials getCredentials(); @PostConstruct void connectToMailServer();  }