Search in sources :

Example 1 with Address

use of org.assertj.core.internal.objects.data.Address in project assertj-core by joel-costigliola.

the class RecursiveComparisonAssert_isEqualTo_withTypeComparators_Test method should_fail_when_actual_differs_from_expected_when_using_comparators_by_type.

@Test
void should_fail_when_actual_differs_from_expected_when_using_comparators_by_type() {
    // 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 type that will fail the comparison
    recursiveComparisonConfiguration.registerComparatorForType(new AlwaysDifferentComparator<>(), Date.class);
    recursiveComparisonConfiguration.registerEqualsForType((Address a1, Address a2) -> false, Address.class);
    // WHEN
    compareRecursivelyFailsAsExpected(actual, expected);
    // THEN
    ComparisonDifference dateOfBirthDifference = diff("dateOfBirth", actual.dateOfBirth, expected.dateOfBirth);
    ComparisonDifference addressDifference = diff("home.address", actual.home.address, expected.home.address);
    ComparisonDifference neighbourAddressDifference = diff("neighbour.home.address", actual.neighbour.home.address, expected.neighbour.home.address);
    verifyShouldBeEqualByComparingFieldByFieldRecursivelyCall(actual, expected, dateOfBirthDifference, addressDifference, neighbourAddressDifference);
}
Also used : Address(org.assertj.core.internal.objects.data.Address) Person(org.assertj.core.internal.objects.data.Person) AlwaysEqualPerson(org.assertj.core.internal.objects.data.AlwaysEqualPerson) Date(java.util.Date) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Date (java.util.Date)1 RecursiveComparisonAssert_isEqualTo_BaseTest (org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)1 Address (org.assertj.core.internal.objects.data.Address)1 AlwaysEqualPerson (org.assertj.core.internal.objects.data.AlwaysEqualPerson)1 Person (org.assertj.core.internal.objects.data.Person)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1