Merge pull request #2229 from philipwhiuk/encodedPersonalTest

AddressTest - Refactor and test UTF-8 encoding
This commit is contained in:
cketti 2017-02-15 00:40:57 +01:00 committed by GitHub
commit 56adeb8129

View file

@ -19,8 +19,9 @@ public class AddressTest {
* http://code.google.com/p/k9mail/issues/detail?id=3814
*/
@Test
public void testParseWithMissingEmail() {
public void parse_withMissingEmail__shouldSetPersonal() {
Address[] addresses = Address.parse("NAME ONLY");
assertEquals(1, addresses.length);
assertEquals(null, addresses[0].getAddress());
assertEquals("NAME ONLY", addresses[0].getPersonal());
@ -30,15 +31,16 @@ public class AddressTest {
* test name + valid email
*/
@Test
public void testParseWithValidEmail() {
public void parse_withValidEmailAndPersonal_shouldSetBoth() {
Address[] addresses = Address.parse("Max Mustermann <maxmuster@mann.com>");
assertEquals(1, addresses.length);
assertEquals("maxmuster@mann.com", addresses[0].getAddress());
assertEquals("Max Mustermann", addresses[0].getPersonal());
}
@Test
public void testParseUnusualEmails() {
public void parse_withUnusualEmails_shouldSetAddress() {
String[] testEmails = new String [] {
"prettyandsimple@example.com",
"very.common@example.com",
@ -61,18 +63,40 @@ public class AddressTest {
"user@localserver",
"user@[IPv6:2001:db8::1]"
};
for(String testEmail: testEmails) {
Address[] addresses = Address.parse("Anonymous <"+testEmail+">");
assertEquals(1, addresses.length);
assertEquals(testEmail, addresses[0].getAddress());
}
}
@Test
public void parse_withEncodedPersonal_shouldDecode() {
Address[] addresses = Address.parse(
"=?UTF-8?B?WWFob28h44OA44Kk44Os44Kv44OI44Kq44OV44Kh44O8?= <directoffer-master@mail.yahoo.co.jp>");
assertEquals("Yahoo!ダイレクトオファー", addresses[0].getPersonal());
assertEquals("directoffer-master@mail.yahoo.co.jp", addresses[0].getAddress());
}
@Test
public void parse_withQuotedEncodedPersonal_shouldDecode() {
Address[] addresses = Address.parse(
"\"=?UTF-8?B?WWFob28h44OA44Kk44Os44Kv44OI44Kq44OV44Kh44O8?= \"<directoffer-master@mail.yahoo.co.jp>");
assertEquals("Yahoo!ダイレクトオファー ", addresses[0].getPersonal());
assertEquals("directoffer-master@mail.yahoo.co.jp", addresses[0].getAddress());
}
/**
* test with multi email addresses
*/
@Test
public void testParseWithValidEmailMulti() {
public void parse_withMultipleEmails_shouldDecodeBoth() {
Address[] addresses = Address.parse("lorem@ipsum.us,mark@twain.com");
assertEquals(2, addresses.length);
assertEquals("lorem@ipsum.us", addresses[0].getAddress());