use of org.assertj.core.internal.objects.data.Person in project assertj-core by joel-costigliola.
the class RecursiveComparisonAssert_isEqualTo_ignoringOverriddenEquals_Test method should_fail_when_actual_differs_from_expected_as_some_overridden_equals_methods_are_ignored_by_types.
@Test
void should_fail_when_actual_differs_from_expected_as_some_overridden_equals_methods_are_ignored_by_types() {
// GIVEN
Person actual = new Person();
actual.neighbour = new AlwaysEqualPerson();
actual.neighbour.name = "Jack";
actual.neighbour.home.address = new AlwaysEqualAddress();
actual.neighbour.home.address.number = 123;
Person expected = new Person();
expected.neighbour = new AlwaysEqualPerson();
expected.neighbour.name = "Jim";
expected.neighbour.home.address = new AlwaysEqualAddress();
expected.neighbour.home.address.number = 234;
recursiveComparisonConfiguration.ignoreOverriddenEqualsForTypes(AlwaysEqualPerson.class, AlwaysEqualAddress.class);
// WHEN
compareRecursivelyFailsAsExpected(actual, expected);
// THEN
ComparisonDifference neighbourNameDifference = diff("neighbour.name", actual.neighbour.name, expected.neighbour.name);
ComparisonDifference numberDifference = diff("neighbour.home.address.number", actual.neighbour.home.address.number, expected.neighbour.home.address.number);
verifyShouldBeEqualByComparingFieldByFieldRecursivelyCall(actual, expected, numberDifference, neighbourNameDifference);
}
use of org.assertj.core.internal.objects.data.Person in project assertj-core by joel-costigliola.
the class RecursiveComparisonAssert_isEqualTo_withTypeComparators_Test method recursivelyEqualObjectsWhenUsingTypeComparators.
private static Stream<Arguments> recursivelyEqualObjectsWhenUsingTypeComparators() {
Person person1 = new Person("John");
person1.home.address.number = 1;
Person person2 = new Person("JoHN");
person2.home.address.number = 2;
Person person3 = new Person("John");
person3.home.address.number = 1;
Person person4 = new Person("John");
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;
MapEntry<Class<?>, Comparator<?>> stringComparator = entry(String.class, CaseInsensitiveStringComparator.instance);
MapEntry<Class<?>, Comparator<?>> intComparator = entry(Integer.class, new AlwaysEqualComparator<Integer>());
MapEntry<Class<?>, Comparator<?>> personComparator = entry(Person.class, new AlwaysEqualComparator<Person>());
return Stream.of(arguments(person1, person2, mapOf(stringComparator, intComparator), "same data except int fields and case for strings"), arguments(person3, person4, mapOf(intComparator), "same data except for int fields"), // any neighbour differences should be ignored as we compare persons with AlwaysEqualComparator
arguments(person5, person6, mapOf(personComparator), "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_withTypeComparators_Test method should_treat_timestamp_as_equal_to_date_when_registering_a_Date_symmetric_comparator.
@Test
void should_treat_timestamp_as_equal_to_date_when_registering_a_Date_symmetric_comparator() {
// GIVEN
Person actual = new Person("Fred");
actual.dateOfBirth = new Timestamp(1000L);
Person expected = new Person(actual.name);
expected.dateOfBirth = new Date(1000L);
// THEN
assertThat(actual).usingRecursiveComparison().withComparatorForType(SYMMETRIC_DATE_COMPARATOR, Timestamp.class).isEqualTo(expected);
assertThat(expected).usingRecursiveComparison().withComparatorForType(SYMMETRIC_DATE_COMPARATOR, Timestamp.class).isEqualTo(actual);
}
use of org.assertj.core.internal.objects.data.Person in project assertj-core by joel-costigliola.
the class RecursiveComparisonAssert_isEqualTo_ignoringOverriddenEquals_Test method should_fail_when_actual_differs_from_expected_as_some_overridden_equals_methods_are_ignored_by_fields.
@Test
void should_fail_when_actual_differs_from_expected_as_some_overridden_equals_methods_are_ignored_by_fields() {
// GIVEN
Person actual = new Person();
actual.neighbour = new AlwaysEqualPerson();
actual.neighbour.name = "Jack";
actual.neighbour.home.address = new AlwaysEqualAddress();
actual.neighbour.home.address.number = 123;
Person expected = new Person();
expected.neighbour = new AlwaysEqualPerson();
expected.neighbour.name = "Jim";
expected.neighbour.home.address = new AlwaysEqualAddress();
expected.neighbour.home.address.number = 234;
recursiveComparisonConfiguration.ignoreOverriddenEqualsForFields("neighbour", "neighbour.home.address");
// WHEN
compareRecursivelyFailsAsExpected(actual, expected);
// THEN
ComparisonDifference neighbourNameDifference = diff("neighbour.name", actual.neighbour.name, expected.neighbour.name);
ComparisonDifference numberDifference = diff("neighbour.home.address.number", actual.neighbour.home.address.number, expected.neighbour.home.address.number);
verifyShouldBeEqualByComparingFieldByFieldRecursivelyCall(actual, expected, numberDifference, neighbourNameDifference);
}
use of org.assertj.core.internal.objects.data.Person in project assertj-core by joel-costigliola.
the class RecursiveComparisonAssert_isEqualTo_usingOverriddenEquals_Test method should_pass_when_using_overridden_equals.
private static Stream<Arguments> should_pass_when_using_overridden_equals() {
Person person1 = new AlwaysEqualPerson();
person1.neighbour = new Person("John");
Person person2 = new AlwaysEqualPerson();
person2.neighbour = new Person("Jack");
Person person3 = new Person();
person3.neighbour = new AlwaysEqualPerson();
person3.neighbour.name = "John";
Person person4 = new Person();
person4.neighbour = new AlwaysEqualPerson();
person4.neighbour.name = "Jack";
return Stream.of(arguments(person1, person2, "root Person is AlwaysEqualPerson"), arguments(person3, person4, "neighbour Person is AlwaysEqualPerson"));
}
Aggregations