AddressesArrayToMailAddressListConverter { public static List<MailAddress> getAddressesAsMailAddress(Address[] addresses) { if (addresses == null) { return ImmutableList.of(); } return Arrays.asList(addresses) .stream() .map(address -> toMailAddress(address)) .flatMap(Optional::stream) .collect(Guavate.toImmutableList()); }  static List<MailAddress> getAddressesAsMailAddress(Address[] addresses);  }
@Test public void getAddressesAsMailAddressShouldReturnEmptyOnNull() { assertThat(AddressesArrayToMailAddressListConverter.getAddressesAsMailAddress(null)).isEmpty(); }
@Test public void getAddressesAsMailAddressShouldReturnEmptyOnEmpty() { assertThat(AddressesArrayToMailAddressListConverter.getAddressesAsMailAddress(new Address[]{})).isEmpty(); }
@Test public void getAddressesAsMailAddressShouldWorkWithSingleValue() throws Exception { assertThat(AddressesArrayToMailAddressListConverter.getAddressesAsMailAddress(new Address[]{ new InternetAddress(MailAddressFixture.ANY_AT_JAMES.toString())})) .containsOnly(MailAddressFixture.ANY_AT_JAMES); }
@Test public void getAddressesAsMailAddressShouldWorkWithTwoValues() throws Exception { assertThat(AddressesArrayToMailAddressListConverter.getAddressesAsMailAddress(new Address[]{ new InternetAddress(MailAddressFixture.ANY_AT_JAMES.toString()), new InternetAddress(MailAddressFixture.OTHER_AT_JAMES.toString())})) .containsOnly(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES); }
@Test public void getAddressesAsMailAddressShouldFilterErrorMailAddress() throws Exception { assertThat(AddressesArrayToMailAddressListConverter.getAddressesAsMailAddress(new Address[]{ new InternetAddress(MailAddressFixture.ANY_AT_JAMES.toString()), new InternetAddress(WRONG_INTERNET_ADDRESS)})) .containsOnly(MailAddressFixture.ANY_AT_JAMES); }