boolean matchesIgnoreCase(AddressHeader other) { boolean sameAddress = OptionalUtils.matches(address, other.address, String::equalsIgnoreCase); boolean samePersonal = OptionalUtils.matches(personal, other.personal, String::equalsIgnoreCase); boolean personalMatchesAddress = OptionalUtils.matches(personal, other.address, String::equalsIgnoreCase); boolean addressMatchesPersonal = OptionalUtils.matches(address, other.personal, String::equalsIgnoreCase); return fullAddress.equalsIgnoreCase(other.fullAddress) || (sameAddress && samePersonal) || (sameAddress && !personal.isPresent()) || (samePersonal && !address.isPresent()) || (personalMatchesAddress && sameAddress) || (addressMatchesPersonal && samePersonal); } }
@Test void matchesShouldReturnFalseWhenSecondOptionalIsEmpty() { assertThat( OptionalUtils.matches( Optional.of(42), Optional.empty(), Integer::equals)) .isFalse(); }
@Test void matchesShouldReturnFalseWhenConditionIsNotMatching() { assertThat( OptionalUtils.matches( Optional.of(42), Optional.of(43), Integer::equals)) .isFalse(); }
@Test void matchesShouldReturnTrueWhenConditionIsMatching() { assertThat( OptionalUtils.matches( Optional.of(42), Optional.of(42), Integer::equals)) .isTrue(); }
@Test void matchesShouldReturnFalseWhenFirstOptionalIsEmpty() { assertThat( OptionalUtils.matches( Optional.empty(), Optional.of(42), Integer::equals)) .isFalse(); }
@Test void matchesShouldReturnFalseWhenBothOptionalsAreEmpty() { assertThat( OptionalUtils.matches( Optional.empty(), Optional.empty(), Integer::equals)) .isFalse(); }