1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Convert to JUnit4

This commit is contained in:
Jan Berkel 2015-01-14 03:09:00 +01:00
parent 0f312f012e
commit 0153766dd5

View File

@ -5,78 +5,83 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import android.support.test.runner.AndroidJUnit4;
import com.fsck.k9.endtoend.framework.StubMailServer; import com.fsck.k9.endtoend.framework.StubMailServer;
import com.fsck.k9.endtoend.framework.UserForImap; import com.fsck.k9.endtoend.framework.UserForImap;
import com.fsck.k9.mail.AuthType; import com.fsck.k9.mail.AuthType;
import com.fsck.k9.mail.AuthenticationFailedException; import com.fsck.k9.mail.AuthenticationFailedException;
import com.fsck.k9.mail.ConnectionSecurity; import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.MessagingException; import com.fsck.k9.mail.MessagingException;
import junit.framework.TestCase; import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
public class ImapConnectionTest extends TestCase { @RunWith(AndroidJUnit4.class)
public class ImapConnectionTest {
private static final String[] CAPABILITIES = new String[] { "IMAP4REV1", "LITERAL+", "QUOTA" }; 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; private TestImapSettings settings;
@Override @Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
stubMailServer = new StubMailServer(); stubMailServer = new StubMailServer();
settings = new TestImapSettings(UserForImap.TEST_USER); settings = new TestImapSettings(UserForImap.TEST_USER);
connection = new ImapConnection(settings, null, null); connection = new ImapConnection(settings, null, null);
} }
@Override @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
super.tearDown();
stubMailServer.stop(); stubMailServer.stop();
} }
@Test(expected = MessagingException.class)
public void testOpenConnectionWithoutRunningServerThrowsMessagingException() throws Exception { public void testOpenConnectionWithoutRunningServerThrowsMessagingException() throws Exception {
stubMailServer.stop(); stubMailServer.stop();
try { connection.open();
connection.open();
fail("expected exception");
} catch (MessagingException e) {
assertFalse(connection.isOpen());
}
} }
@Test(expected = AuthenticationFailedException.class)
public void testOpenConnectionWithWrongCredentialsThrowsAuthenticationFailedException() 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 { connection.open();
connection.open();
fail("expected exception");
} catch (AuthenticationFailedException e) {
assertTrue(e.getMessage().contains("Invalid login/password"));
assertFalse(connection.isOpen());
}
} }
@Test
public void testConnectionIsInitiallyClosed() throws Exception { public void testConnectionIsInitiallyClosed() throws Exception {
assertFalse(connection.isOpen()); assertFalse(connection.isOpen());
} }
@Test
public void testSuccessfulOpenConnectionTogglesOpenState() throws Exception { public void testSuccessfulOpenConnectionTogglesOpenState() throws Exception {
connection.open(); connection.open();
assertTrue(connection.isOpen()); assertTrue(connection.isOpen());
} }
@Test
public void testSuccessfulOpenAndCloseConnectionTogglesOpenState() throws Exception { public void testSuccessfulOpenAndCloseConnectionTogglesOpenState() throws Exception {
connection.open(); connection.open();
connection.close(); connection.close();
assertFalse(connection.isOpen()); assertFalse(connection.isOpen());
} }
@Test
public void testCapabilitiesAreInitiallyEmpty() throws Exception { public void testCapabilitiesAreInitiallyEmpty() throws Exception {
assertTrue(connection.getCapabilities().isEmpty()); assertTrue(connection.getCapabilities().isEmpty());
} }
@Test
public void testCapabilitiesListGetsParsedCorrectly() throws Exception { 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());
@ -84,6 +89,7 @@ public class ImapConnectionTest extends TestCase {
assertArrayEquals(CAPABILITIES, capabilities.toArray()); assertArrayEquals(CAPABILITIES, capabilities.toArray());
} }
@Test
public void testHasCapabilityChecks() throws Exception { public void testHasCapabilityChecks() throws Exception {
connection.open(); connection.open();
for (String capability : CAPABILITIES) { for (String capability : CAPABILITIES) {
@ -92,16 +98,19 @@ public class ImapConnectionTest extends TestCase {
assertFalse(connection.hasCapability("FROBAZIFCATE")); assertFalse(connection.hasCapability("FROBAZIFCATE"));
} }
@Test
public void testPathPrefixGetsSetCorrectly() throws Exception { public void testPathPrefixGetsSetCorrectly() throws Exception {
connection.open(); connection.open();
assertEquals("", settings.getPathPrefix()); assertEquals("", settings.getPathPrefix());
} }
@Test
public void testPathDelimiterGetsParsedCorrectly() throws Exception { public void testPathDelimiterGetsParsedCorrectly() throws Exception {
connection.open(); connection.open();
assertEquals(".", settings.getPathDelimiter()); assertEquals(".", settings.getPathDelimiter());
} }
@Test
public void testCombinedPrefixGetsSetCorrectly() throws Exception { public void testCombinedPrefixGetsSetCorrectly() throws Exception {
connection.open(); connection.open();
assertNull(settings.getCombinedPrefix()); assertNull(settings.getCombinedPrefix());