Emailer { public static Builder builder() { return new Builder(); } @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(expected = IllegalStateException.class) public void buildShouldThrowWhenNameIsNull() { Emailer.builder().build(); }
@Test(expected = IllegalStateException.class) public void buildShouldThrowWhenEmailIsNull() { Emailer.builder().build(); }
@Test(expected = IllegalStateException.class) public void buildShouldThrowWhenNameIsEmpty() { Emailer.builder().name("").email("email@domain").build(); }
@Test(expected = IllegalStateException.class) public void buildShouldThrowWhenEmailIsEmpty() { Emailer.builder().name("name").email("").build(); }
@Test(expected = IllegalStateException.class) public void buildShouldThrowWhenEmailWithoutArobase() { Emailer.builder().name("name").email("email.without.arobase").build(); }
@Test public void buildShouldWork() { Emailer expected = new Emailer(Optional.of("name"), Optional.of("user@domain")); Emailer emailer = Emailer.builder() .name("name") .email("user@domain") .build(); assertThat(emailer).isEqualToComparingFieldByField(expected); }
@Test public void buildInvalidAllowedShouldConsiderNullValuesAsInvalid() { Emailer expected = new Emailer(Optional.empty(), Optional.empty()); Emailer actual = Emailer.builder() .allowInvalid() .build(); assertThat(actual).isEqualToComparingFieldByField(expected); }
@Test public void buildInvalidAllowedShouldConsiderEmptyValuesAsInvalid() { Emailer expected = new Emailer(Optional.empty(), Optional.empty()); Emailer actual = Emailer.builder() .name("") .email("") .allowInvalid() .build(); assertThat(actual).isEqualToComparingFieldByField(expected); }
@Test public void buildInvalidAllowedShouldDeclareInvalidAddressesAsInvalid() { Emailer expected = new Emailer(Optional.empty(), Optional.of("invalidAddress")); Emailer actual = Emailer.builder() .email("invalidAddress") .allowInvalid() .build(); assertThat(actual).isEqualToComparingFieldByField(expected); }
@Test public void buildInvalidAllowedShouldWork() { String name = "bob"; String address = "me@apache.org"; Emailer expected = new Emailer(Optional.of(name), Optional.of(address)); Emailer actual = Emailer.builder() .name(name) .email(address) .allowInvalid() .build(); assertThat(actual).isEqualToComparingFieldByField(expected); }