1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Add more tests + descriptive names

This commit is contained in:
Jan Berkel 2015-01-13 01:59:51 +01:00
parent 111212b391
commit 60070b7883

View File

@ -16,6 +16,8 @@ import static org.junit.Assert.assertArrayEquals;
public class ImapConnectionTest extends TestCase { public class ImapConnectionTest extends TestCase {
private static final String[] CAPABILITIES = new String[] { "IMAP4REV1", "LITERAL+", "QUOTA" };
private StubMailServer stubMailServer; private StubMailServer stubMailServer;
private ImapConnection connection; private ImapConnection connection;
private TestImapSettings settings = new TestImapSettings(UserForImap.TEST_USER); private TestImapSettings settings = new TestImapSettings(UserForImap.TEST_USER);
@ -24,8 +26,7 @@ public class ImapConnectionTest extends TestCase {
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
stubMailServer = new StubMailServer(); stubMailServer = new StubMailServer();
connection = new ImapConnection(settings, null, connection = new ImapConnection(settings, null, null);
null);
} }
@Override @Override
@ -34,7 +35,7 @@ public class ImapConnectionTest extends TestCase {
stubMailServer.stop(); stubMailServer.stop();
} }
public void testOpenConnectionWithWrongCredentials() throws Exception { public void testOpenConnectionWithWrongCredentialsThrowsAuthenticationFailedException() throws Exception {
connection = new ImapConnection(new TestImapSettings("wrong", "password"), null, null); connection = new ImapConnection(new TestImapSettings("wrong", "password"), null, null);
try { try {
connection.open(); connection.open();
@ -45,22 +46,34 @@ public class ImapConnectionTest extends TestCase {
} }
} }
public void testOpenConnection() throws Exception { public void testSuccessfulOpenConnectionTogglesOpenState() throws Exception {
connection.open(); connection.open();
assertTrue(connection.isOpen()); assertTrue(connection.isOpen());
} }
public void testOpenAndCloseConnection() throws Exception { public void testSuccessfulOpenAndCloseConnectionTogglesOpenState() throws Exception {
connection.open(); connection.open();
connection.close(); connection.close();
assertFalse(connection.isOpen()); assertFalse(connection.isOpen());
} }
public void testCapabilities() throws Exception { public void testCapabilitiesAreInitiallyEmpty() throws Exception {
assertTrue(connection.getCapabilities().isEmpty());
}
public void testCapabilitiesListGetsParsedCorrectly() throws Exception {
connection.open(); connection.open();
List<String> capabilities = new ArrayList<String>(connection.getCapabilities()); List<String> capabilities = new ArrayList<String>(connection.getCapabilities());
Collections.sort(capabilities); Collections.sort(capabilities);
assertArrayEquals(new String[] { "IMAP4REV1", "LITERAL+", "QUOTA" }, capabilities.toArray()); assertArrayEquals(CAPABILITIES, capabilities.toArray());
}
public void testHasCapabilityChecks() throws Exception {
connection.open();
for (String capability : CAPABILITIES) {
assertTrue(connection.hasCapability(capability));
}
assertFalse(connection.hasCapability("FROBAZIFCATE"));
} }
public void testPathPrefixGetsSetCorrectly() throws Exception { public void testPathPrefixGetsSetCorrectly() throws Exception {
@ -73,11 +86,17 @@ public class ImapConnectionTest extends TestCase {
assertEquals(".", settings.getPathDelimiter()); assertEquals(".", settings.getPathDelimiter());
} }
public void testCombinedPrefixGetsSetCorrectly() throws Exception {
connection.open();
assertNull(settings.getCombinedPrefix());
}
private class TestImapSettings implements ImapSettings { private class TestImapSettings implements ImapSettings {
private String pathPrefix; private String pathPrefix;
private String pathDelimiter; private String pathDelimiter;
private String username; private String username;
private String password; private String password;
private String combinedPrefix;
public TestImapSettings(UserForImap userForImap) { public TestImapSettings(UserForImap userForImap) {
this(userForImap.loginUsername, userForImap.password); this(userForImap.loginUsername, userForImap.password);
@ -150,11 +169,12 @@ public class ImapConnectionTest extends TestCase {
@Override @Override
public String getCombinedPrefix() { public String getCombinedPrefix() {
return null; return combinedPrefix;
} }
@Override @Override
public void setCombinedPrefix(String prefix) { public void setCombinedPrefix(String prefix) {
combinedPrefix = prefix;
} }
} }
} }