private ImapConnection simpleOpenWithCapabilities(MockImapServer server, String postAuthCapabilities) throws Exception { simpleOpenDialog(server, postAuthCapabilities); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); return imapConnection; }
@Test public void executeSingleCommand_withOkResponse_shouldReturnResult() throws Exception { MockImapServer server = new MockImapServer(); simpleOpenDialog(server, ""); server.expect("4 CREATE Folder"); server.output("4 OK Folder created"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); List<ImapResponse> result = imapConnection.executeSimpleCommand("CREATE Folder"); assertEquals(result.size(), 1); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); }
@Test public void hasCapability_withNotYetOpenedConnection_shouldConnectAndFetchCapabilities() throws Exception { MockImapServer server = new MockImapServer(); simpleOpenDialog(server, "X-SOMETHING"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); boolean capabilityPresent = imapConnection.hasCapability("X-SOMETHING"); assertTrue(capabilityPresent); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); }
@Test public void executeSingleCommand_withNoResponse_shouldThrowNegativeImapResponseException() throws Exception { MockImapServer server = new MockImapServer(); simpleOpenDialog(server, ""); server.expect("4 CREATE Folder"); server.output("4 NO Folder exists"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); try { imapConnection.executeSimpleCommand("CREATE Folder"); fail("Expected exception"); } catch (NegativeImapResponseException e) { assertEquals("Folder exists", e.getLastResponse().getString(1)); } server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); }
@Test public void sendContinuation() throws Exception { settings.setAuthType(AuthType.PLAIN); MockImapServer server = new MockImapServer(); simpleOpenDialog(server, "IDLE"); server.expect("4 IDLE"); server.output("+ idling"); server.expect("DONE"); ImapConnection imapConnection = startServerAndCreateImapConnection(server); imapConnection.open(); imapConnection.sendCommand("IDLE", false); imapConnection.readResponse(); imapConnection.sendContinuation("DONE"); server.waitForInteractionToComplete(); server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); }