Emailer { public static Optional<Emailer> firstFromMailboxList(MailboxList list) { return Optional.ofNullable(list) .flatMap(mailboxes -> mailboxes.stream() .map(Emailer::fromMailbox) .findFirst()); } @VisibleForTesting  Emailer(Optional<String> name, Optional<String> email); static List<Emailer> fromAddressList(AddressList list); static Optional<Emailer> firstFromMailboxList(MailboxList list); static Builder builder(); Optional<String> getName(); Optional<String> getEmail(); @JsonIgnore MailAddress toMailAddress(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void firstFromMailboxListShouldReturnEmptyWhenNullMailboxList() { assertThat(Emailer.firstFromMailboxList(null)) .isEmpty(); }