use of org.assertj.core.internal.objects.data.Person in project assertj-core by joel-costigliola.
the class RecursiveComparisonConfiguration_getActualNonIgnoreFields_Test method should_compute_ignored_fields.
@Test
void should_compute_ignored_fields() {
// GIVEN
recursiveComparisonConfiguration.ignoreFieldsMatchingRegexes(".*umber");
recursiveComparisonConfiguration.ignoreFields("people.name");
recursiveComparisonConfiguration.ignoreFieldsOfTypes(Date.class);
Person person1 = new Person("John");
person1.home.address.number = 1;
person1.dateOfBirth = new Date(123);
person1.neighbour = new Person("Jack");
person1.neighbour.home.address.number = 123;
Person person2 = new Person("John");
person2.home.address.number = 1;
person2.dateOfBirth = new Date(123);
person2.neighbour = new Person("Jim");
person2.neighbour.home.address.number = 456;
DualValue dualValue = new DualValue(list("people"), person1, person2);
// WHEN
Set<String> fields = recursiveComparisonConfiguration.getNonIgnoredActualFieldNames(dualValue);
// THEN
assertThat(fields).doesNotContain("number", "dateOfBirth", "name");
}
use of org.assertj.core.internal.objects.data.Person in project assertj-core by joel-costigliola.
the class RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test method should_fail_when_actual_differs_from_expected_when_using_field_bipredicate_comparators.
@Test
void should_fail_when_actual_differs_from_expected_when_using_field_bipredicate_comparators() {
// GIVEN
Person actual = new Person("John");
actual.home.address.number = 1;
actual.dateOfBirth = new Date(123);
actual.neighbour = new Person("Jack");
actual.neighbour.home.address.number = 123;
// actually a clone of actual
Person expected = new Person("John");
expected.home.address.number = 1;
expected.dateOfBirth = new Date(123);
expected.neighbour = new Person("Jack");
expected.neighbour.home.address.number = 123;
// register some equals methods for some fields that will fail the comparison
recursiveComparisonConfiguration.registerEqualsForFields((Object o1, Object o2) -> false, "dateOfBirth", "neighbour.home.address");
// WHEN
compareRecursivelyFailsAsExpected(actual, expected);
// THEN
ComparisonDifference dateOfBirthDifference = diff("dateOfBirth", actual.dateOfBirth, expected.dateOfBirth);
ComparisonDifference neighbourAddressDifference = diff("neighbour.home.address", actual.neighbour.home.address, expected.neighbour.home.address);
verifyShouldBeEqualByComparingFieldByFieldRecursivelyCall(actual, expected, dateOfBirthDifference, neighbourAddressDifference);
}
use of org.assertj.core.internal.objects.data.Person in project assertj-core by joel-costigliola.
the class RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test method recursivelyEqualObjectsWhenUsingFieldComparators.
private static Stream<Arguments> recursivelyEqualObjectsWhenUsingFieldComparators() {
Person person1 = new Person("John");
person1.home.address.number = 1;
Person person2 = new Person("JoHN");
person2.home.address.number = 1;
Person person3 = new Person("John");
person3.home.address.number = 1;
Person person4 = new Person("Jack");
person4.home.address.number = 2;
Person person5 = new Person("John");
person5.home.address.number = 1;
person5.dateOfBirth = new Date(123);
person5.neighbour = new Person("Jack");
person5.neighbour.home.address.number = 123;
Person person6 = new Person("John");
person6.home.address.number = 1;
person6.dateOfBirth = new Date(123);
person6.neighbour = new Person("Jim");
person6.neighbour.home.address.number = 456;
return Stream.of(arguments(person1, person2, CaseInsensitiveStringComparator.instance, array("name"), "same data except int fields and case for strings"), arguments(person3, person4, alwaysEqual(), array("name", "home.address.number"), "same data except for int fields"), // any neighbour differences should be ignored as we compare persons with AlwaysEqualComparator
arguments(person5, person6, alwaysEqual(), array("neighbour"), "same data except for persons, person's fields should not be compared recursively except at the root level"));
}
use of org.assertj.core.internal.objects.data.Person in project assertj-core by joel-costigliola.
the class RecursiveComparisonAssert_isEqualTo_withErrorMessageForFields_Test method field_message_should_take_precedence_over_type_message.
@Test
void field_message_should_take_precedence_over_type_message() {
// GIVEN
Person actual = new Person("Valera");
actual.age = OptionalInt.of(15);
Person expected = new Person("John");
expected.age = OptionalInt.of(15);
String fieldMessage = "Name must be the same";
String fieldLocation = "name";
String typeMessage = "Type message has to be ignored";
// WHEN
AssertionError assertionError = expectAssertionError(() -> assertThat(actual).usingRecursiveComparison().withErrorMessageForFields(fieldMessage, fieldLocation).withErrorMessageForType(typeMessage, String.class).isEqualTo(expected));
// THEN
then(assertionError).hasMessageContainingAll(fieldMessage, ERROR_MESSAGE_DESCRIPTION_FOR_FIELDS, "- " + fieldLocation, ERROR_MESSAGE_PRECEDENCE_DESCRIPTION_FOR_FIELDS).hasMessageNotContainingAny(typeMessage);
}
use of org.assertj.core.internal.objects.data.Person in project assertj-core by joel-costigliola.
the class RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test method should_fail_when_actual_differs_from_expected_when_using_field_comparators.
@Test
void should_fail_when_actual_differs_from_expected_when_using_field_comparators() {
// GIVEN
Person actual = new Person("John");
actual.home.address.number = 1;
actual.dateOfBirth = new Date(123);
actual.neighbour = new Person("Jack");
actual.neighbour.home.address.number = 123;
// actually a clone of actual
Person expected = new Person("John");
expected.home.address.number = 1;
expected.dateOfBirth = new Date(123);
expected.neighbour = new Person("Jack");
expected.neighbour.home.address.number = 123;
// register comparators for some fields that will fail the comparison
recursiveComparisonConfiguration.registerComparatorForFields(alwaysDifferent(), "dateOfBirth", "neighbour.home.address");
// WHEN
compareRecursivelyFailsAsExpected(actual, expected);
// THEN
ComparisonDifference dateOfBirthDifference = diff("dateOfBirth", actual.dateOfBirth, expected.dateOfBirth);
ComparisonDifference neighbourAddressDifference = diff("neighbour.home.address", actual.neighbour.home.address, expected.neighbour.home.address);
verifyShouldBeEqualByComparingFieldByFieldRecursivelyCall(actual, expected, dateOfBirthDifference, neighbourAddressDifference);
}
Aggregations