### Question:
ListHeaders { public static Address[] getListPostAddresses(Message message) { String[] headerValues = message.getHeader(LIST_POST_HEADER); if (headerValues.length < 1) { return new Address[0]; } List<Address> listPostAddresses = new ArrayList<>(); for (String headerValue : headerValues) { Address address = extractAddress(headerValue); if (address != null) { listPostAddresses.add(address); } } return listPostAddresses.toArray(new Address[listPostAddresses.size()]); }  static Address[] getListPostAddresses(Message message); static final String LIST_POST_HEADER; }### Answer:
@Test public void getListPostAddresses_withMailTo_shouldReturnCorrectAddress() throws Exception { for (String emailAddress : TEST_EMAIL_ADDRESSES) { String headerValue = "<mailto:" + emailAddress + ">"; Message message = buildMimeMessageWithListPostValue(headerValue); Address[] result = ListHeaders.getListPostAddresses(message); assertExtractedAddressMatchesEmail(emailAddress, result); } }
@Test public void getListPostAddresses_withMailtoWithNote_shouldReturnCorrectAddress() throws Exception { for (String emailAddress : TEST_EMAIL_ADDRESSES) { String headerValue = "<mailto:" + emailAddress + "> (Postings are Moderated)"; Message message = buildMimeMessageWithListPostValue(headerValue); Address[] result = ListHeaders.getListPostAddresses(message); assertExtractedAddressMatchesEmail(emailAddress, result); } }
@Test public void getListPostAddresses_withMailtoWithSubject_shouldReturnCorrectAddress() throws Exception { for (String emailAddress : TEST_EMAIL_ADDRESSES) { String headerValue = "<mailto:" + emailAddress + "?subject=list%20posting>"; Message message = buildMimeMessageWithListPostValue(headerValue); Address[] result = ListHeaders.getListPostAddresses(message); assertExtractedAddressMatchesEmail(emailAddress, result); } }
@Test public void getListPostAddresses_withMessageWithNo_shouldReturnEmptyList() throws Exception { MimeMessage message = buildMimeMessageWithListPostValue("NO (posting not allowed on this list)"); Address[] result = ListHeaders.getListPostAddresses(message); assertEquals(0, result.length); }
@Test public void getListPostAddresses_shouldProvideAllListPostHeaders() throws Exception { MimeMessage message = buildMimeMessageWithListPostValue( "<mailto:list1@example.org>", "<mailto:list2@example.org>"); Address[] result = ListHeaders.getListPostAddresses(message); assertNotNull(result); assertEquals(2, result.length); assertNotNull(result[0]); assertEquals("list1@example.org", result[0].getAddress()); assertNotNull(result[1]); assertEquals("list2@example.org", result[1].getAddress()); }
@Test public void getListPostAddresses_withoutMailtoUriInBrackets_shouldReturnEmptyList() throws Exception { MimeMessage message = buildMimeMessageWithListPostValue("<x-mailto:something>"); Address[] result = ListHeaders.getListPostAddresses(message); assertEquals(0, result.length); }