### Question:
EMailLogic { public int getNewMessageCount(boolean checkForImportant) { if (checkForImportant) { return getNewImportantMessages().size(); } return getNewMessages().size(); }  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();  }### Answer:
@Test public void testGetNewMessageCountNormalCase() throws MessagingException, IOException { Message[] messages1 = createMockMessages(15, 7); when(this.inboxMock.search(ArgumentMatchers.any(FlagTerm.class))).thenReturn(messages1); assertEquals(15, this.emailLogic.getNewMessageCount(false)); assertEquals(7, this.emailLogic.getNewMessageCount(true)); Message[] messages2 = createMockMessages(10, 0); when(this.inboxMock.search(ArgumentMatchers.any(FlagTerm.class))).thenReturn(messages2); assertEquals(10, this.emailLogic.getNewMessageCount(false)); assertEquals(0, this.emailLogic.getNewMessageCount(true)); Message[] messages3 = createMockMessages(10, 10); when(this.inboxMock.search(ArgumentMatchers.any(FlagTerm.class))).thenReturn(messages3); assertEquals(10, this.emailLogic.getNewMessageCount(false)); assertEquals(10, this.emailLogic.getNewMessageCount(true)); }
@Test public void testGetNewMessageCountNoMails() throws MessagingException { when(this.inboxMock.search(ArgumentMatchers.any(FlagTerm.class))).thenReturn(new Message[0]); assertEquals(0, this.emailLogic.getNewMessageCount(false)); assertEquals(0, this.emailLogic.getNewMessageCount(true)); }