From 66dd4990b181bd45c41a72a29e1ad9406b840c5f Mon Sep 17 00:00:00 2001 From: Jan Berkel Date: Thu, 18 Dec 2014 11:56:02 +0100 Subject: [PATCH] Move tests to JVM + convert to modern syntax --- tests-on-jvm/build.gradle | 1 + tests-on-jvm/src/android/util/Log.java | 1 + .../src/com/fsck/k9/mail/AddressTest.java | 13 +- .../com/fsck/k9/mail/Address_quoteAtoms.java | 10 +- .../filter/EOLConvertingOutputStreamTest.java | 27 +- .../k9/mail/internet/CharsetSupportTest.java | 10 +- .../k9/mail/internet/DecoderUtilTest.java | 9 +- .../mail/internet/MimeMessageParseTest.java | 342 +++++++++--------- .../k9/mail/internet/MimeUtilityTest.java | 9 +- .../fsck/k9/mail/store/imap/ImapListTest.java | 12 +- .../k9/mail/store/imap/ImapStoreUriTest.java | 25 +- .../k9/mail/store/imap/ImapUtilityTest.java | 67 ++-- .../k9/mail/internet/DecoderUtilTest.java | 111 ------ .../k9/mail/internet/MimeUtilityTest.java | 42 --- 14 files changed, 277 insertions(+), 402 deletions(-) rename {tests => tests-on-jvm}/src/com/fsck/k9/mail/AddressTest.java (82%) rename {tests => tests-on-jvm}/src/com/fsck/k9/mail/Address_quoteAtoms.java (88%) rename {tests => tests-on-jvm}/src/com/fsck/k9/mail/internet/MimeMessageParseTest.java (93%) rename {tests => tests-on-jvm}/src/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java (87%) rename {tests => tests-on-jvm}/src/com/fsck/k9/mail/store/imap/ImapUtilityTest.java (67%) delete mode 100644 tests/src/com/fsck/k9/mail/internet/DecoderUtilTest.java delete mode 100644 tests/src/com/fsck/k9/mail/internet/MimeUtilityTest.java diff --git a/tests-on-jvm/build.gradle b/tests-on-jvm/build.gradle index 23e8608ef..e4fc7cb11 100644 --- a/tests-on-jvm/build.gradle +++ b/tests-on-jvm/build.gradle @@ -18,6 +18,7 @@ sourceSets { test { compileClasspath += files(rootProject.compileDebugJava.destinationDir) + compileClasspath += rootProject.compileDebugJava.classpath runtimeClasspath += files(rootProject.compileDebugJava.destinationDir) runtimeClasspath += rootProject.compileDebugJava.classpath java { diff --git a/tests-on-jvm/src/android/util/Log.java b/tests-on-jvm/src/android/util/Log.java index abb17e99d..4d952eb26 100644 --- a/tests-on-jvm/src/android/util/Log.java +++ b/tests-on-jvm/src/android/util/Log.java @@ -3,6 +3,7 @@ package android.util; public class Log { public static int v(String tag, String message) { return 0; } public static int d(String tag, String message) { return 0; } + public static int d(String tag, String message, Throwable throwable) { return 0; } public static int i(String tag, String message) { return 0; } public static int w(String tag, String message) { return 0; } public static int e(String tag, String message) { return 0; } diff --git a/tests/src/com/fsck/k9/mail/AddressTest.java b/tests-on-jvm/src/com/fsck/k9/mail/AddressTest.java similarity index 82% rename from tests/src/com/fsck/k9/mail/AddressTest.java rename to tests-on-jvm/src/com/fsck/k9/mail/AddressTest.java index e1a3778e1..1be326490 100644 --- a/tests/src/com/fsck/k9/mail/AddressTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/AddressTest.java @@ -1,13 +1,16 @@ package com.fsck.k9.mail; -import junit.framework.TestCase; -public class AddressTest extends TestCase { +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class AddressTest { /** * test the possibility to parse "From:" fields with no email. * for example: From: News for Vector Limited - Google Finance * http://code.google.com/p/k9mail/issues/detail?id=3814 */ - public void testParseWithMissingEmail() { + @Test public void testParseWithMissingEmail() { Address[] addresses = Address.parse("NAME ONLY"); assertEquals(1, addresses.length); assertEquals(null, addresses[0].getAddress()); @@ -17,7 +20,7 @@ public class AddressTest extends TestCase { /** * test name + valid email */ - public void testPraseWithValidEmail() { + @Test public void testPraseWithValidEmail() { Address[] addresses = Address.parse("Max Mustermann "); assertEquals(1, addresses.length); assertEquals("maxmuster@mann.com", addresses[0].getAddress()); @@ -26,7 +29,7 @@ public class AddressTest extends TestCase { /** * test with multi email addresses */ - public void testPraseWithValidEmailMulti() { + @Test public void testPraseWithValidEmailMulti() { Address[] addresses = Address.parse("lorem@ipsum.us,mark@twain.com"); assertEquals(2, addresses.length); assertEquals("lorem@ipsum.us", addresses[0].getAddress()); diff --git a/tests/src/com/fsck/k9/mail/Address_quoteAtoms.java b/tests-on-jvm/src/com/fsck/k9/mail/Address_quoteAtoms.java similarity index 88% rename from tests/src/com/fsck/k9/mail/Address_quoteAtoms.java rename to tests-on-jvm/src/com/fsck/k9/mail/Address_quoteAtoms.java index 0ea553b2e..498b4756d 100644 --- a/tests/src/com/fsck/k9/mail/Address_quoteAtoms.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/Address_quoteAtoms.java @@ -1,10 +1,13 @@ package com.fsck.k9.mail; -import junit.framework.TestCase; -public class Address_quoteAtoms extends TestCase +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class Address_quoteAtoms { - public void testNoQuote() { + @Test public void testNoQuote() { // Alpha noQuote("a"); noQuote("aa"); @@ -47,6 +50,7 @@ public class Address_quoteAtoms extends TestCase noQuote("'-=+=-'"); } + @Test public void testQuote() { assertEquals("\"bob s. barker\"", quote("bob s. barker")); assertEquals("\":(\"", quote(":(")); diff --git a/tests-on-jvm/src/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java b/tests-on-jvm/src/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java index ebb9dac64..c9bc3c41d 100644 --- a/tests-on-jvm/src/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/filter/EOLConvertingOutputStreamTest.java @@ -1,51 +1,54 @@ package com.fsck.k9.mail.filter; -import junit.framework.TestCase; + +import org.junit.Before; +import org.junit.Test; import java.io.ByteArrayOutputStream; -public class EOLConvertingOutputStreamTest extends TestCase { +import static org.junit.Assert.assertEquals; + +public class EOLConvertingOutputStreamTest { private EOLConvertingOutputStream subject; private ByteArrayOutputStream out; - @Override + @Before public void setUp() throws Exception { - super.setUp(); out = new ByteArrayOutputStream(); subject = new EOLConvertingOutputStream(out); } - public void testFilterWithoutCRorLF() throws Exception { + @Test public void testFilterWithoutCRorLF() throws Exception { subject.write("Unchanged".getBytes()); subject.flush(); assertEquals("Unchanged", out.toString()); } - public void testFilterWithCRLF() throws Exception { + @Test public void testFilterWithCRLF() throws Exception { subject.write("Filter\r\nNext Line".getBytes()); subject.flush(); assertEquals("Filter\r\nNext Line", out.toString()); } - public void testFilterWithJustCR() throws Exception { + @Test public void testFilterWithJustCR() throws Exception { subject.write("\n\n\n".getBytes()); subject.flush(); assertEquals("\r\n\r\n\r\n", out.toString()); } - public void testFilterWithCR() throws Exception { + @Test public void testFilterWithCR() throws Exception { subject.write("Filter\rNext Line".getBytes()); subject.flush(); assertEquals("Filter\r\nNext Line", out.toString()); } - public void testFilterWithLF() throws Exception { + @Test public void testFilterWithLF() throws Exception { subject.write("Filter\nNext Line".getBytes()); subject.flush(); assertEquals("Filter\r\nNext Line", out.toString()); } - public void testFlushWithCR() throws Exception { + @Test public void testFlushWithCR() throws Exception { subject.write("Flush\r".getBytes()); subject.flush(); assertEquals("Flush\r\n", out.toString()); @@ -53,14 +56,14 @@ public class EOLConvertingOutputStreamTest extends TestCase { assertEquals("Flush\r\n\r\n\r\n", out.toString()); } - public void testFlushWithCRNotFollowedByLF() throws Exception { + @Test public void testFlushWithCRNotFollowedByLF() throws Exception { subject.write("Flush\r".getBytes()); subject.flush(); subject.write("Next line".getBytes()); assertEquals("Flush\r\nNext line", out.toString()); } - public void testFlushWithLF() throws Exception { + @Test public void testFlushWithLF() throws Exception { subject.write("Flush\n".getBytes()); subject.flush(); subject.write("\n".getBytes()); diff --git a/tests-on-jvm/src/com/fsck/k9/mail/internet/CharsetSupportTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/CharsetSupportTest.java index dcf65dd8a..316138d03 100644 --- a/tests-on-jvm/src/com/fsck/k9/mail/internet/CharsetSupportTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/CharsetSupportTest.java @@ -1,10 +1,13 @@ package com.fsck.k9.mail.internet; -import junit.framework.TestCase; -public class CharsetSupportTest extends TestCase { +import org.junit.Test; - public void testFixupCharset() throws Exception { +import static org.junit.Assert.assertEquals; + +public class CharsetSupportTest { + + @Test public void testFixupCharset() throws Exception { String charsetOnMail; String expect; @@ -89,6 +92,5 @@ public class CharsetSupportTest extends TestCase { charsetOnMail = "shift_jis"; expect = "x-kddi-shift_jis-2007"; assertEquals(expect, CharsetSupport.fixupCharset(charsetOnMail, message)); - } } diff --git a/tests-on-jvm/src/com/fsck/k9/mail/internet/DecoderUtilTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/DecoderUtilTest.java index e0e4feea5..21660992b 100644 --- a/tests-on-jvm/src/com/fsck/k9/mail/internet/DecoderUtilTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/DecoderUtilTest.java @@ -1,10 +1,13 @@ package com.fsck.k9.mail.internet; -import junit.framework.TestCase; -public class DecoderUtilTest extends TestCase { +import org.junit.Test; - public void testDecodeEncodedWords() { +import static org.junit.Assert.assertEquals; + +public class DecoderUtilTest { + + @Test public void testDecodeEncodedWords() { String body, expect; MimeMessage message; diff --git a/tests/src/com/fsck/k9/mail/internet/MimeMessageParseTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/MimeMessageParseTest.java similarity index 93% rename from tests/src/com/fsck/k9/mail/internet/MimeMessageParseTest.java rename to tests-on-jvm/src/com/fsck/k9/mail/internet/MimeMessageParseTest.java index 4558d4264..028912f25 100644 --- a/tests/src/com/fsck/k9/mail/internet/MimeMessageParseTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/MimeMessageParseTest.java @@ -9,22 +9,190 @@ import java.util.Collections; import java.util.List; import org.apache.commons.io.IOUtils; +import org.junit.Before; +import org.junit.Test; import com.fsck.k9.mail.Address; import com.fsck.k9.mail.Body; import com.fsck.k9.mail.BodyPart; import com.fsck.k9.mail.Message.RecipientType; import com.fsck.k9.mail.Multipart; -import com.fsck.k9.mail.internet.MimeMessage; -import android.test.AndroidTestCase; +import static org.junit.Assert.assertEquals; -public class MimeMessageParseTest extends AndroidTestCase { - static { +public class MimeMessageParseTest { + @Before + public void setup() { BinaryTempFileBody.setTempDirectory(new File(System.getProperty("java.io.tmpdir"))); } + @Test public void testSinglePart7BitNoRecurse() throws Exception { + MimeMessage msg = parseWithoutRecurse(toStream( + "From: \r\n" + + "To: \r\n" + + "Subject: Testmail\r\n" + + "MIME-Version: 1.0\r\n" + + "Content-type: text/plain\r\n" + + "Content-Transfer-Encoding: 7bit\r\n" + + "\r\n" + + "this is some test text.")); + + checkAddresses(msg.getFrom(), "adam@example.org"); + checkAddresses(msg.getRecipients(RecipientType.TO), "eva@example.org"); + assertEquals("Testmail", msg.getSubject()); + assertEquals("text/plain", msg.getContentType()); + assertEquals("this is some test text.", streamToString(msg.getBody().getInputStream())); + } + + @Test public void testSinglePart8BitRecurse() throws Exception { + MimeMessage msg = parseWithRecurse(toStream( + "From: \r\n" + + "To: \r\n" + + "Subject: Testmail\r\n" + + "MIME-Version: 1.0\r\n" + + "Content-type: text/plain; encoding=ISO-8859-1\r\n" + + "Content-Transfer-Encoding: 8bit\r\n" + + "\r\n" + + "gefährliche Umlaute")); + + checkAddresses(msg.getFrom(), "adam@example.org"); + checkAddresses(msg.getRecipients(RecipientType.TO), "eva@example.org"); + assertEquals("Testmail", msg.getSubject()); + assertEquals("text/plain; encoding=ISO-8859-1", msg.getContentType()); + assertEquals("gefährliche Umlaute", streamToString(msg.getBody().getInputStream())); + } + + @Test public void testSinglePartBase64NoRecurse() throws Exception { + MimeMessage msg = parseWithoutRecurse(toStream( + "From: \r\n" + + "To: \r\n" + + "Subject: Testmail\r\n" + + "MIME-Version: 1.0\r\n" + + "Content-type: text/plain\r\n" + + "Content-Transfer-Encoding: base64\r\n" + + "\r\n" + + "dGhpcyBpcyBzb21lIG1vcmUgdGVzdCB0ZXh0Lg==\r\n")); + + checkAddresses(msg.getFrom(), "adam@example.org"); + checkAddresses(msg.getRecipients(RecipientType.TO), "eva@example.org"); + assertEquals("Testmail", msg.getSubject()); + assertEquals("text/plain", msg.getContentType()); + assertEquals("this is some more test text.", streamToString(msg.getBody().getInputStream())); + } + + @Test public void testMultipartSingleLayerNoRecurse() throws Exception { + MimeMessage msg = parseWithoutRecurse(toStream( + "From: \r\n" + + "To: \r\n" + + "Subject: Testmail 2\r\n" + + "MIME-Version: 1.0\n" + + "Content-Type: multipart/mixed; boundary=frontier\n" + + "\n" + + "This is a message with multiple parts in MIME format.\n" + + "--frontier\n" + + "Content-Type: text/plain\n" + + "\n" + + "This is the body of the message.\n" + + "--frontier\n" + + "Content-Type: application/octet-stream\n" + + "Content-Transfer-Encoding: base64\n" + + "\n" + + "PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg\n" + + "Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg=\n" + + "--frontier--")); + + checkAddresses(msg.getFrom(), "x@example.org"); + checkAddresses(msg.getRecipients(RecipientType.TO), "y@example.org"); + assertEquals("Testmail 2", msg.getSubject()); + assertEquals("multipart/mixed; boundary=frontier", msg.getContentType()); + checkLeafParts(msg, + "This is the body of the message.", + "\n" + + " \n" + + " \n" + + " \n" + + "

This is the body of the message.

\n" + + " \n" + + "\n" + + ""); + } + + @Test public void testMultipartSingleLayerRecurse() throws Exception { + MimeMessage msg = parseWithRecurse(toStream( + "From: \r\n" + + "To: \r\n" + + "Subject: Testmail 2\r\n" + + "MIME-Version: 1.0\n" + + "Content-Type: multipart/mixed; boundary=frontier\n" + + "\n" + + "This is a message with multiple parts in MIME format.\n" + + "--frontier\n" + + "Content-Type: text/plain\n" + + "\n" + + "This is the body of the message.\n" + + "--frontier\n" + + "Content-Type: application/octet-stream\n" + + "Content-Transfer-Encoding: base64\n" + + "\n" + + "PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg\n" + + "Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg=\n" + + "--frontier--")); + + checkAddresses(msg.getFrom(), "x@example.org"); + checkAddresses(msg.getRecipients(RecipientType.TO), "y@example.org"); + assertEquals("Testmail 2", msg.getSubject()); + assertEquals("multipart/mixed; boundary=frontier", msg.getContentType()); + checkLeafParts(msg, + "This is the body of the message.", + "\n" + + " \n" + + " \n" + + " \n" + + "

This is the body of the message.

\n" + + " \n" + + "\n" + + ""); + } + + @Test public void testMultipartTwoLayersRecurse() throws Exception { + MimeMessage msg = parseWithRecurse(toStream( + "From: \r\n" + + "To: \r\n" + + "Subject: Testmail 2\r\n" + + "MIME-Version: 1.0\n" + + "Content-Type: multipart/mixed; boundary=1\n" + + "\n" + + "This is a message with multiple parts in MIME format.\n" + + "--1\n" + + "Content-Type: text/plain\n" + + "\n" + + "some text in the first part\n" + + "--1\n" + + "Content-Type: multipart/alternative; boundary=2\n" + + "\n" + + "--2\n" + + "Content-Type: text/plain\n" + + "\n" + + "alternative 1\n" + + "--2\n" + + "Content-Type: text/plain\n" + + "\n" + + "alternative 2\n" + + "--2--\n" + + "--1--")); + + checkAddresses(msg.getFrom(), "x@example.org"); + checkAddresses(msg.getRecipients(RecipientType.TO), "y@example.org"); + assertEquals("Testmail 2", msg.getSubject()); + assertEquals("multipart/mixed; boundary=1", msg.getContentType()); + checkLeafParts(msg, + "some text in the first part", + "alternative 1", + "alternative 2"); + } + + private static ByteArrayInputStream toStream(String rawMailData) throws Exception { return new ByteArrayInputStream(rawMailData.getBytes("ISO-8859-1")); } @@ -67,170 +235,4 @@ public class MimeMessageParseTest extends AndroidTestCase { } assertEquals(Arrays.asList(expectedParts), actual); } - - public static void testSinglePart7BitNoRecurse() throws Exception { - MimeMessage msg = parseWithoutRecurse(toStream( - "From: \r\n" + - "To: \r\n" + - "Subject: Testmail\r\n" + - "MIME-Version: 1.0\r\n" + - "Content-type: text/plain\r\n" + - "Content-Transfer-Encoding: 7bit\r\n" + - "\r\n" + - "this is some test text.")); - - checkAddresses(msg.getFrom(), "adam@example.org"); - checkAddresses(msg.getRecipients(RecipientType.TO), "eva@example.org"); - assertEquals("Testmail", msg.getSubject()); - assertEquals("text/plain", msg.getContentType()); - assertEquals("this is some test text.", streamToString(msg.getBody().getInputStream())); - } - - public static void testSinglePart8BitRecurse() throws Exception { - MimeMessage msg = parseWithRecurse(toStream( - "From: \r\n" + - "To: \r\n" + - "Subject: Testmail\r\n" + - "MIME-Version: 1.0\r\n" + - "Content-type: text/plain; encoding=ISO-8859-1\r\n" + - "Content-Transfer-Encoding: 8bit\r\n" + - "\r\n" + - "gefährliche Umlaute")); - - checkAddresses(msg.getFrom(), "adam@example.org"); - checkAddresses(msg.getRecipients(RecipientType.TO), "eva@example.org"); - assertEquals("Testmail", msg.getSubject()); - assertEquals("text/plain; encoding=ISO-8859-1", msg.getContentType()); - assertEquals("gefährliche Umlaute", streamToString(msg.getBody().getInputStream())); - } - - public static void testSinglePartBase64NoRecurse() throws Exception { - MimeMessage msg = parseWithoutRecurse(toStream( - "From: \r\n" + - "To: \r\n" + - "Subject: Testmail\r\n" + - "MIME-Version: 1.0\r\n" + - "Content-type: text/plain\r\n" + - "Content-Transfer-Encoding: base64\r\n" + - "\r\n" + - "dGhpcyBpcyBzb21lIG1vcmUgdGVzdCB0ZXh0Lg==\r\n")); - - checkAddresses(msg.getFrom(), "adam@example.org"); - checkAddresses(msg.getRecipients(RecipientType.TO), "eva@example.org"); - assertEquals("Testmail", msg.getSubject()); - assertEquals("text/plain", msg.getContentType()); - assertEquals("this is some more test text.", streamToString(msg.getBody().getInputStream())); - } - - public static void testMultipartSingleLayerNoRecurse() throws Exception { - MimeMessage msg = parseWithoutRecurse(toStream( - "From: \r\n" + - "To: \r\n" + - "Subject: Testmail 2\r\n" + - "MIME-Version: 1.0\n" + - "Content-Type: multipart/mixed; boundary=frontier\n" + - "\n" + - "This is a message with multiple parts in MIME format.\n" + - "--frontier\n" + - "Content-Type: text/plain\n" + - "\n" + - "This is the body of the message.\n" + - "--frontier\n" + - "Content-Type: application/octet-stream\n" + - "Content-Transfer-Encoding: base64\n" + - "\n" + - "PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg\n" + - "Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg=\n" + - "--frontier--")); - - checkAddresses(msg.getFrom(), "x@example.org"); - checkAddresses(msg.getRecipients(RecipientType.TO), "y@example.org"); - assertEquals("Testmail 2", msg.getSubject()); - assertEquals("multipart/mixed; boundary=frontier", msg.getContentType()); - checkLeafParts(msg, - "This is the body of the message.", - "\n" + - " \n" + - " \n" + - " \n" + - "

This is the body of the message.

\n" + - " \n" + - "\n" + - ""); - } - - public static void testMultipartSingleLayerRecurse() throws Exception { - MimeMessage msg = parseWithRecurse(toStream( - "From: \r\n" + - "To: \r\n" + - "Subject: Testmail 2\r\n" + - "MIME-Version: 1.0\n" + - "Content-Type: multipart/mixed; boundary=frontier\n" + - "\n" + - "This is a message with multiple parts in MIME format.\n" + - "--frontier\n" + - "Content-Type: text/plain\n" + - "\n" + - "This is the body of the message.\n" + - "--frontier\n" + - "Content-Type: application/octet-stream\n" + - "Content-Transfer-Encoding: base64\n" + - "\n" + - "PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg\n" + - "Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg=\n" + - "--frontier--")); - - checkAddresses(msg.getFrom(), "x@example.org"); - checkAddresses(msg.getRecipients(RecipientType.TO), "y@example.org"); - assertEquals("Testmail 2", msg.getSubject()); - assertEquals("multipart/mixed; boundary=frontier", msg.getContentType()); - checkLeafParts(msg, - "This is the body of the message.", - "\n" + - " \n" + - " \n" + - " \n" + - "

This is the body of the message.

\n" + - " \n" + - "\n" + - ""); - } - - public static void testMultipartTwoLayersRecurse() throws Exception { - MimeMessage msg = parseWithRecurse(toStream( - "From: \r\n" + - "To: \r\n" + - "Subject: Testmail 2\r\n" + - "MIME-Version: 1.0\n" + - "Content-Type: multipart/mixed; boundary=1\n" + - "\n" + - "This is a message with multiple parts in MIME format.\n" + - "--1\n" + - "Content-Type: text/plain\n" + - "\n" + - "some text in the first part\n" + - "--1\n" + - "Content-Type: multipart/alternative; boundary=2\n" + - "\n" + - "--2\n" + - "Content-Type: text/plain\n" + - "\n" + - "alternative 1\n" + - "--2\n" + - "Content-Type: text/plain\n" + - "\n" + - "alternative 2\n" + - "--2--\n" + - "--1--")); - - checkAddresses(msg.getFrom(), "x@example.org"); - checkAddresses(msg.getRecipients(RecipientType.TO), "y@example.org"); - assertEquals("Testmail 2", msg.getSubject()); - assertEquals("multipart/mixed; boundary=1", msg.getContentType()); - checkLeafParts(msg, - "some text in the first part", - "alternative 1", - "alternative 2"); - } - } diff --git a/tests-on-jvm/src/com/fsck/k9/mail/internet/MimeUtilityTest.java b/tests-on-jvm/src/com/fsck/k9/mail/internet/MimeUtilityTest.java index 7b86df546..a94a2d449 100644 --- a/tests-on-jvm/src/com/fsck/k9/mail/internet/MimeUtilityTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/internet/MimeUtilityTest.java @@ -1,9 +1,12 @@ package com.fsck.k9.mail.internet; -import junit.framework.TestCase; -public class MimeUtilityTest extends TestCase { - public void testGetHeaderParameter() { +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class MimeUtilityTest { + @Test public void testGetHeaderParameter() { String result; /* Test edge cases */ diff --git a/tests-on-jvm/src/com/fsck/k9/mail/store/imap/ImapListTest.java b/tests-on-jvm/src/com/fsck/k9/mail/store/imap/ImapListTest.java index 050a7fb87..618baf5f9 100644 --- a/tests-on-jvm/src/com/fsck/k9/mail/store/imap/ImapListTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/store/imap/ImapListTest.java @@ -1,11 +1,17 @@ package com.fsck.k9.mail.store.imap; -import junit.framework.TestCase; +import org.junit.Test; import java.io.IOException; -public class ImapListTest extends TestCase { - public void testImapListMethods() throws IOException { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class ImapListTest { + @Test public void testImapListMethods() throws IOException { ImapList list = new ImapList(); list.add("ONE"); list.add("TWO"); diff --git a/tests/src/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java b/tests-on-jvm/src/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java similarity index 87% rename from tests/src/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java rename to tests-on-jvm/src/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java index b10380a7a..49507de36 100644 --- a/tests/src/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java @@ -8,10 +8,13 @@ import com.fsck.k9.mail.ConnectionSecurity; import com.fsck.k9.mail.ServerSettings; import com.fsck.k9.mail.store.RemoteStore; -import junit.framework.TestCase; +import org.junit.Test; -public class ImapStoreUriTest extends TestCase { - public void testDecodeStoreUriImapAllExtras() { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class ImapStoreUriTest { + @Test public void testDecodeStoreUriImapAllExtras() { String uri = "imap://PLAIN:user:pass@server:143/0%7CcustomPathPrefix"; ServerSettings settings = RemoteStore.decodeStoreUri(uri); @@ -24,7 +27,7 @@ public class ImapStoreUriTest extends TestCase { assertEquals("customPathPrefix", settings.getExtra().get("pathPrefix")); } - public void testDecodeStoreUriImapNoExtras() { + @Test public void testDecodeStoreUriImapNoExtras() { String uri = "imap://PLAIN:user:pass@server:143/"; ServerSettings settings = RemoteStore.decodeStoreUri(uri); @@ -36,7 +39,7 @@ public class ImapStoreUriTest extends TestCase { assertEquals("true", settings.getExtra().get("autoDetectNamespace")); } - public void testDecodeStoreUriImapPrefixOnly() { + @Test public void testDecodeStoreUriImapPrefixOnly() { String uri = "imap://PLAIN:user:pass@server:143/customPathPrefix"; ServerSettings settings = RemoteStore.decodeStoreUri(uri); @@ -49,7 +52,7 @@ public class ImapStoreUriTest extends TestCase { assertEquals("customPathPrefix", settings.getExtra().get("pathPrefix")); } - public void testDecodeStoreUriImapEmptyPrefix() { + @Test public void testDecodeStoreUriImapEmptyPrefix() { String uri = "imap://PLAIN:user:pass@server:143/0%7C"; ServerSettings settings = RemoteStore.decodeStoreUri(uri); @@ -62,7 +65,7 @@ public class ImapStoreUriTest extends TestCase { assertEquals("", settings.getExtra().get("pathPrefix")); } - public void testDecodeStoreUriImapAutodetectAndPrefix() { + @Test public void testDecodeStoreUriImapAutodetectAndPrefix() { String uri = "imap://PLAIN:user:pass@server:143/1%7CcustomPathPrefix"; ServerSettings settings = RemoteStore.decodeStoreUri(uri); @@ -76,7 +79,7 @@ public class ImapStoreUriTest extends TestCase { } - public void testCreateStoreUriImapPrefix() { + @Test public void testCreateStoreUriImapPrefix() { Map extra = new HashMap(); extra.put("autoDetectNamespace", "false"); extra.put("pathPrefix", "customPathPrefix"); @@ -89,7 +92,7 @@ public class ImapStoreUriTest extends TestCase { assertEquals("imap://PLAIN:user:pass@server:143/0%7CcustomPathPrefix", uri); } - public void testCreateStoreUriImapEmptyPrefix() { + @Test public void testCreateStoreUriImapEmptyPrefix() { Map extra = new HashMap(); extra.put("autoDetectNamespace", "false"); extra.put("pathPrefix", ""); @@ -102,7 +105,7 @@ public class ImapStoreUriTest extends TestCase { assertEquals("imap://PLAIN:user:pass@server:143/0%7C", uri); } - public void testCreateStoreUriImapNoExtra() { + @Test public void testCreateStoreUriImapNoExtra() { ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null); @@ -111,7 +114,7 @@ public class ImapStoreUriTest extends TestCase { assertEquals("imap://PLAIN:user:pass@server:143/1%7C", uri); } - public void testCreateStoreUriImapAutoDetectNamespace() { + @Test public void testCreateStoreUriImapAutoDetectNamespace() { Map extra = new HashMap(); extra.put("autoDetectNamespace", "true"); diff --git a/tests/src/com/fsck/k9/mail/store/imap/ImapUtilityTest.java b/tests-on-jvm/src/com/fsck/k9/mail/store/imap/ImapUtilityTest.java similarity index 67% rename from tests/src/com/fsck/k9/mail/store/imap/ImapUtilityTest.java rename to tests-on-jvm/src/com/fsck/k9/mail/store/imap/ImapUtilityTest.java index 6f891cffd..283660fbb 100644 --- a/tests/src/com/fsck/k9/mail/store/imap/ImapUtilityTest.java +++ b/tests-on-jvm/src/com/fsck/k9/mail/store/imap/ImapUtilityTest.java @@ -17,15 +17,15 @@ package com.fsck.k9.mail.store.imap; +import org.junit.Test; + import java.util.List; -import android.test.MoreAsserts; -import junit.framework.TestCase; +import static org.junit.Assert.assertArrayEquals; -public class ImapUtilityTest extends TestCase { - /** - * Test getting elements of an IMAP sequence set. - */ + +public class ImapUtilityTest { + @Test public void testGetImapSequenceValues() { String[] expected; List actual; @@ -33,116 +33,113 @@ public class ImapUtilityTest extends TestCase { // Test valid sets expected = new String[] {"1"}; actual = ImapUtility.getImapSequenceValues("1"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[] {"2147483648"}; // Integer.MAX_VALUE + 1 actual = ImapUtility.getImapSequenceValues("2147483648"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[] {"4294967295"}; // 2^32 - 1 actual = ImapUtility.getImapSequenceValues("4294967295"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[] {"1", "3", "2"}; actual = ImapUtility.getImapSequenceValues("1,3,2"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[] {"4", "5", "6"}; actual = ImapUtility.getImapSequenceValues("4:6"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[] {"9", "8", "7"}; actual = ImapUtility.getImapSequenceValues("9:7"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[] {"1", "2", "3", "4", "9", "8", "7"}; actual = ImapUtility.getImapSequenceValues("1,2:4,9:7"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); // Test numbers larger than Integer.MAX_VALUE (2147483647) expected = new String[] {"2147483646", "2147483647", "2147483648"}; actual = ImapUtility.getImapSequenceValues("2147483646:2147483648"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); // Test partially invalid sets expected = new String[] { "1", "5" }; actual = ImapUtility.getImapSequenceValues("1,x,5"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[] { "1", "2", "3" }; actual = ImapUtility.getImapSequenceValues("a:d,1:3"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); // Test invalid sets expected = new String[0]; actual = ImapUtility.getImapSequenceValues(""); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapSequenceValues(null); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapSequenceValues("a"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapSequenceValues("1:x"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); // Test values larger than 2^32 - 1 expected = new String[0]; actual = ImapUtility.getImapSequenceValues("4294967296:4294967297"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapSequenceValues("4294967296"); // 2^32 - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); } - /** - * Test getting elements of an IMAP range. - */ - public void testGetImapRangeValues() { + @Test public void testGetImapRangeValues() { String[] expected; List actual; // Test valid ranges expected = new String[] {"1", "2", "3"}; actual = ImapUtility.getImapRangeValues("1:3"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[] {"16", "15", "14"}; actual = ImapUtility.getImapRangeValues("16:14"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); // Test in-valid ranges expected = new String[0]; actual = ImapUtility.getImapRangeValues(""); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapRangeValues(null); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapRangeValues("a"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapRangeValues("6"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapRangeValues("1:3,6"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapRangeValues("1:x"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); expected = new String[0]; actual = ImapUtility.getImapRangeValues("1:*"); - MoreAsserts.assertEquals(expected, actual.toArray()); + assertArrayEquals(expected, actual.toArray()); } } diff --git a/tests/src/com/fsck/k9/mail/internet/DecoderUtilTest.java b/tests/src/com/fsck/k9/mail/internet/DecoderUtilTest.java deleted file mode 100644 index b1d25c873..000000000 --- a/tests/src/com/fsck/k9/mail/internet/DecoderUtilTest.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.fsck.k9.mail.internet; - -import junit.framework.TestCase; - -public class DecoderUtilTest extends TestCase { - - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void testDecodeEncodedWords() { - String body, expect; - MimeMessage message; - - body = "abc"; - expect = "abc"; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=?us-ascii?q?abc?="; - expect = "abc"; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=?"; - expect = "=?"; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=??"; - expect = "=??"; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=???"; - expect = "=???"; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=????"; - expect = "=????"; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=????="; - expect = "=????="; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=??q??="; - expect = "=??q??=";; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=??q?a?="; - expect = "a"; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=??="; - expect = "=??="; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=?x?="; - expect = "=?x?="; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=?x??="; - expect = "=?x??="; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=?x?q?="; - expect = "=?x?q?="; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=?x?q??="; - expect = "=?x?q??="; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=?x?q?X?="; - expect = "X"; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - // invalid base64 string - body = "=?us-ascii?b?abc?="; - expect = ""; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - // broken encoded header - body = "=?us-ascii?q?abc?= =?"; - expect = "abc =?"; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - - body = "=?x?= =?"; - expect = "=?x?= =?"; - message = null; - assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message)); - } -} diff --git a/tests/src/com/fsck/k9/mail/internet/MimeUtilityTest.java b/tests/src/com/fsck/k9/mail/internet/MimeUtilityTest.java deleted file mode 100644 index 900daec60..000000000 --- a/tests/src/com/fsck/k9/mail/internet/MimeUtilityTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.fsck.k9.mail.internet; - -import android.test.AndroidTestCase; - -public class MimeUtilityTest extends AndroidTestCase { - - public void testGetHeaderParameter() { - String result; - - /* Test edge cases */ - result = MimeUtility.getHeaderParameter(";", null); - assertEquals(null, result); - - result = MimeUtility.getHeaderParameter("name", "name"); - assertEquals(null, result); - - result = MimeUtility.getHeaderParameter("name=", "name"); - assertEquals("", result); - - result = MimeUtility.getHeaderParameter("name=\"", "name"); - assertEquals("\"", result); - - /* Test expected cases */ - result = MimeUtility.getHeaderParameter("name=value", "name"); - assertEquals("value", result); - - result = MimeUtility.getHeaderParameter("name = value", "name"); - assertEquals("value", result); - - result = MimeUtility.getHeaderParameter("name=\"value\"", "name"); - assertEquals("value", result); - - result = MimeUtility.getHeaderParameter("name = \"value\"" , "name"); - assertEquals("value", result); - - result = MimeUtility.getHeaderParameter("name=\"\"", "name"); - assertEquals("", result); - - result = MimeUtility.getHeaderParameter("text/html ; charset=\"windows-1251\"", null); - assertEquals("text/html", result); - } -}