public void testSinglePack() { Address[] addrArray = new Address[1]; for (Address address : new Address[] {ADDR_1, ADDR_2, ADDR_3}) { String packed1 = address.toHeader(); addrArray[0] = address; String packed2 = Address.toHeader(addrArray); assertEquals(packed1, packed2); } }
/** * Simple quick checks of empty-input edge conditions for pack() * * <p>NOTE: This is not a claim that these edge cases are "correct", only to maintain consistent * behavior while I am changing some of the code in the function under test. */ public void testEmptyToHeader() { String result; // null input => null string result = Address.toHeader(null); assertNull("packing null", result); // zero-length input => null string result = Address.toHeader(new Address[] {}); assertNull("packing empty array", result); }
/** * Tests that: 1. firstAddress() with empty list returns null. 2. firstAddress() with non-empty * returns the same as fromHeader()[0] */ public void testFirstAddress() { assertNull(Address.firstAddress(null)); assertNull(Address.firstAddress("")); for (Address[] list : TO_HEADER_CASES) { String packed = Address.toHeader(list); Address[] array = Address.fromHeader(packed); Address first = Address.firstAddress(packed); assertTrue(packed, addressEquals(array[0], first)); } }
/** Tests that fromHeaderToString() returns the same result as toString(fromHeader()). */ public void testFromHeaderToString() { assertNull(Address.fromHeaderToString(null)); assertNull(Address.fromHeaderToString("")); for (Address[] list : TO_HEADER_CASES) { String packed = Address.toHeader(list); String s1 = Address.fromHeaderToString(packed); String s2 = Address.toString(Address.fromHeader(packed)); assertEquals(s2, s2, s1); } }
/** Test various combinations of the toHeader (multi) method */ public void testToHeaderMulti() { Address noName1 = new Address("*****@*****.**"); Address noName2 = new Address("<*****@*****.**>", ""); Address simpleName = new Address("*****@*****.**", "simple name"); Address dquoteName = new Address("*****@*****.**", "name,4"); Address quotedName = new Address("*****@*****.**", "big \"G\""); Address utf16Name = new Address("<*****@*****.**>", "\"\u65E5\u672C\u8A9E\""); Address utf32Name = new Address("<*****@*****.**>", "\uD834\uDF01\uD834\uDF46"); // test for internal states. assertEquals("no name 1 address", "*****@*****.**", noName1.getAddress()); assertNull("no name 1 name", noName1.getPersonal()); assertEquals("no name 2 address", "*****@*****.**", noName2.getAddress()); assertNull("no name 2 name", noName2.getPersonal()); assertEquals("simple name address", "*****@*****.**", simpleName.getAddress()); assertEquals("simple name name", "simple name", simpleName.getPersonal()); assertEquals("double quoted name address", "*****@*****.**", dquoteName.getAddress()); assertEquals("double quoted name name", "name,4", dquoteName.getPersonal()); assertEquals("quoted name address", "*****@*****.**", quotedName.getAddress()); assertEquals("quoted name name", "big \"G\"", quotedName.getPersonal()); assertEquals("utf-16 name address", "*****@*****.**", utf16Name.getAddress()); assertEquals("utf-16 name name", "\u65E5\u672C\u8A9E", utf16Name.getPersonal()); assertEquals("utf-32 name address", "*****@*****.**", utf32Name.getAddress()); assertEquals("utf-32 name name", "\uD834\uDF01\uD834\uDF46", utf32Name.getPersonal()); Address[] addresses = new Address[] { noName1, noName2, simpleName, dquoteName, quotedName, utf16Name, utf32Name, }; String line = Address.toHeader(addresses); assertEquals( "toHeader() multi", "[email protected], " + "[email protected], " + "simple name <*****@*****.**>, " + "\"name,4\" <*****@*****.**>, " + "\"big \\\"G\\\"\" <*****@*****.**>, " + "=?UTF-8?B?5pel5pys6Kqe?= <*****@*****.**>, " + "=?UTF-8?B?8J2MgfCdjYY=?= <*****@*****.**>", line); }
/** Test various combinations of the toHeader (single) method */ public void testToHeaderSingle() { Address noName1 = new Address("*****@*****.**"); Address noName2 = new Address("<*****@*****.**>", ""); Address simpleName = new Address("*****@*****.**", "simple name"); Address dquoteName = new Address("*****@*****.**", "name,4"); Address quotedName = new Address("*****@*****.**", "big \"G\""); Address utf16Name = new Address("<*****@*****.**>", "\"\u65E5\u672C\u8A9E\""); Address utf32Name = new Address("<*****@*****.**>", "\uD834\uDF01\uD834\uDF46"); Address sameName = new Address("*****@*****.**", "*****@*****.**"); // test for internal states. assertEquals("no name 1 address", "*****@*****.**", noName1.getAddress()); assertNull("no name 1 name", noName1.getPersonal()); assertEquals("no name 2 address", "*****@*****.**", noName2.getAddress()); assertNull("no name 2 name", noName2.getPersonal()); assertEquals("simple name address", "*****@*****.**", simpleName.getAddress()); assertEquals("simple name name", "simple name", simpleName.getPersonal()); assertEquals("double quoted name address", "*****@*****.**", dquoteName.getAddress()); assertEquals("double quoted name name", "name,4", dquoteName.getPersonal()); assertEquals("quoted name address", "*****@*****.**", quotedName.getAddress()); assertEquals("quoted name name", "big \"G\"", quotedName.getPersonal()); assertEquals("utf-16 name address", "*****@*****.**", utf16Name.getAddress()); assertEquals("utf-16 name name", "\u65E5\u672C\u8A9E", utf16Name.getPersonal()); assertEquals("utf-32 name address", "*****@*****.**", utf32Name.getAddress()); assertEquals("utf-32 name name", "\uD834\uDF01\uD834\uDF46", utf32Name.getPersonal()); assertEquals("name == address address", "*****@*****.**", sameName.getAddress()); assertEquals("name == address name", "*****@*****.**", sameName.getPersonal()); // Test for toHeader() results. assertEquals("no name 1", "*****@*****.**", noName1.toHeader()); assertEquals("no name 2", "*****@*****.**", noName2.toHeader()); assertEquals("simple name", "simple name <*****@*****.**>", simpleName.toHeader()); assertEquals("double quoted name", "\"name,4\" <*****@*****.**>", dquoteName.toHeader()); assertEquals("quoted name", "\"big \\\"G\\\"\" <*****@*****.**>", quotedName.toHeader()); assertEquals("utf-16 name", "=?UTF-8?B?5pel5pys6Kqe?= <*****@*****.**>", utf16Name.toHeader()); assertEquals("utf-32 name", "=?UTF-8?B?8J2MgfCdjYY=?= <*****@*****.**>", utf32Name.toHeader()); assertEquals("name == address", "\"[email protected]\" <*****@*****.**>", sameName.toHeader()); }
/** Tests that parseToHeader() returns the same result as toHeader(parse()). */ public void testParseAndPack() { String s1 = Address.parseToHeader(MULTI_ADDRESSES_LIST); String s2 = Address.toHeader(Address.parse(MULTI_ADDRESSES_LIST)); assertEquals(s2, s1); }
public void testToHeaderFromHeader() { for (Address[] list : TO_HEADER_CASES) { String packed = Address.toHeader(list); assertTrue(packed, addressArrayEquals(list, Address.fromHeader(packed))); } }