IMAP: Test coverage improvements
This commit is contained in:
parent
8b4fc30f4a
commit
9a6009d8d4
1 changed files with 80 additions and 0 deletions
|
@ -42,6 +42,7 @@ import static org.mockito.Matchers.any;
|
|||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
@ -451,6 +452,24 @@ public class ImapFolderTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUnreadMessageCount_connectionThrowsIOException_shouldThrowMessagingException()
|
||||
throws Exception {
|
||||
ImapFolder folder = createFolder("Folder");
|
||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||
List<ImapResponse> imapResponses = singletonList(createImapResponse("* SEARCH 1 2 3"));
|
||||
when(imapConnection.executeSimpleCommand("SEARCH 1:* UNSEEN NOT DELETED"))
|
||||
.thenThrow(new IOException());
|
||||
folder.open(OPEN_MODE_RW);
|
||||
|
||||
try {
|
||||
folder.getUnreadMessageCount();
|
||||
fail("Expected exception");
|
||||
} catch (MessagingException e) {
|
||||
assertEquals("IO Error", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUnreadMessageCount() throws Exception {
|
||||
ImapFolder folder = createFolder("Folder");
|
||||
|
@ -506,6 +525,36 @@ public class ImapFolderTest {
|
|||
assertEquals(42L, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHighestUid_imapConnectionThrowsNegativesResponse_shouldReturnMinus1() throws Exception {
|
||||
ImapFolder folder = createFolder("Folder");
|
||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||
List<ImapResponse> imapResponses = singletonList(createImapResponse("* SEARCH 42"));
|
||||
when(imapConnection.executeSimpleCommand("UID SEARCH *:*"))
|
||||
.thenThrow(NegativeImapResponseException.class);
|
||||
folder.open(OPEN_MODE_RW);
|
||||
|
||||
long result = folder.getHighestUid();
|
||||
|
||||
assertEquals(-1L, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHighestUid_imapConnectionThrowsIOException_shouldThrowMessagingException() throws Exception {
|
||||
ImapFolder folder = createFolder("Folder");
|
||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||
List<ImapResponse> imapResponses = singletonList(createImapResponse("* SEARCH 42"));
|
||||
when(imapConnection.executeSimpleCommand("UID SEARCH *:*"))
|
||||
.thenThrow(IOException.class);
|
||||
folder.open(OPEN_MODE_RW);
|
||||
|
||||
try {
|
||||
folder.getHighestUid();
|
||||
} catch (MessagingException e) {
|
||||
assertEquals("IO Error", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessages_withoutDateConstraint() throws Exception {
|
||||
ImapFolder folder = createFolder("Folder");
|
||||
|
@ -724,6 +773,18 @@ public class ImapFolderTest {
|
|||
assertFalse(result);
|
||||
}
|
||||
|
||||
public void areMoreMessagesAvailable_withIndexOf1_shouldReturnFalseWithoutPerformingSearch() throws Exception {
|
||||
ImapFolder folder = createFolder("Folder");
|
||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||
folder.open(OPEN_MODE_RW);
|
||||
|
||||
boolean result = folder.areMoreMessagesAvailable(1, null);
|
||||
|
||||
verify(imapConnection, never()).executeSimpleCommand(anyString());
|
||||
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void areMoreMessagesAvailable_withoutAdditionalMessages_shouldIssueSearchCommandsUntilAllMessagesSearched()
|
||||
throws Exception {
|
||||
|
@ -1022,6 +1083,25 @@ public class ImapFolderTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete_notImplemented() throws MessagingException {
|
||||
ImapFolder folder = createFolder("Folder");
|
||||
try {
|
||||
folder.delete(false);
|
||||
fail("Error expected");
|
||||
} catch (Error e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMessageByUid_returnsNewImapMessage() throws MessagingException {
|
||||
ImapFolder folder = createFolder("Folder");
|
||||
ImapMessage message = folder.getMessage("uid");
|
||||
assertNotNull(message);
|
||||
assertEquals("uid", message.getUid());
|
||||
assertEquals(folder, message.getFolder());
|
||||
}
|
||||
|
||||
private Set<String> extractMessageUids(List<ImapMessage> messages) {
|
||||
Set<String> result = new HashSet<>();
|
||||
for (Message message : messages) {
|
||||
|
|
Loading…
Reference in a new issue