mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 09:52:16 -05:00
Move tests to JVM + convert to modern syntax
This commit is contained in:
parent
0a6920c63e
commit
66dd4990b1
@ -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 {
|
||||
|
@ -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; }
|
||||
|
@ -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 <maxmuster@mann.com>");
|
||||
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());
|
@ -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(":("));
|
@ -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());
|
||||
|
@ -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));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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: <adam@example.org>\r\n" +
|
||||
"To: <eva@example.org>\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: <adam@example.org>\r\n" +
|
||||
"To: <eva@example.org>\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: <adam@example.org>\r\n" +
|
||||
"To: <eva@example.org>\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: <x@example.org>\r\n" +
|
||||
"To: <y@example.org>\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.",
|
||||
"<html>\n" +
|
||||
" <head>\n" +
|
||||
" </head>\n" +
|
||||
" <body>\n" +
|
||||
" <p>This is the body of the message.</p>\n" +
|
||||
" </body>\n" +
|
||||
"</html>\n" +
|
||||
"");
|
||||
}
|
||||
|
||||
@Test public void testMultipartSingleLayerRecurse() throws Exception {
|
||||
MimeMessage msg = parseWithRecurse(toStream(
|
||||
"From: <x@example.org>\r\n" +
|
||||
"To: <y@example.org>\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.",
|
||||
"<html>\n" +
|
||||
" <head>\n" +
|
||||
" </head>\n" +
|
||||
" <body>\n" +
|
||||
" <p>This is the body of the message.</p>\n" +
|
||||
" </body>\n" +
|
||||
"</html>\n" +
|
||||
"");
|
||||
}
|
||||
|
||||
@Test public void testMultipartTwoLayersRecurse() throws Exception {
|
||||
MimeMessage msg = parseWithRecurse(toStream(
|
||||
"From: <x@example.org>\r\n" +
|
||||
"To: <y@example.org>\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: <adam@example.org>\r\n" +
|
||||
"To: <eva@example.org>\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: <adam@example.org>\r\n" +
|
||||
"To: <eva@example.org>\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: <adam@example.org>\r\n" +
|
||||
"To: <eva@example.org>\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: <x@example.org>\r\n" +
|
||||
"To: <y@example.org>\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.",
|
||||
"<html>\n" +
|
||||
" <head>\n" +
|
||||
" </head>\n" +
|
||||
" <body>\n" +
|
||||
" <p>This is the body of the message.</p>\n" +
|
||||
" </body>\n" +
|
||||
"</html>\n" +
|
||||
"");
|
||||
}
|
||||
|
||||
public static void testMultipartSingleLayerRecurse() throws Exception {
|
||||
MimeMessage msg = parseWithRecurse(toStream(
|
||||
"From: <x@example.org>\r\n" +
|
||||
"To: <y@example.org>\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.",
|
||||
"<html>\n" +
|
||||
" <head>\n" +
|
||||
" </head>\n" +
|
||||
" <body>\n" +
|
||||
" <p>This is the body of the message.</p>\n" +
|
||||
" </body>\n" +
|
||||
"</html>\n" +
|
||||
"");
|
||||
}
|
||||
|
||||
public static void testMultipartTwoLayersRecurse() throws Exception {
|
||||
MimeMessage msg = parseWithRecurse(toStream(
|
||||
"From: <x@example.org>\r\n" +
|
||||
"To: <y@example.org>\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");
|
||||
}
|
||||
|
||||
}
|
@ -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 */
|
||||
|
@ -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");
|
||||
|
@ -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<String, String> extra = new HashMap<String, String>();
|
||||
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<String, String> extra = new HashMap<String, String>();
|
||||
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<String, String> extra = new HashMap<String, String>();
|
||||
extra.put("autoDetectNamespace", "true");
|
||||
|
@ -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<String> 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<String> 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());
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user