Search in sources :

Example 1 with AlwaysEqualPerson

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

the class RecursiveComparisonAssert_isEqualTo_Test method should_not_use_equal_implementation_of_root_objects_to_compare.

@Test
void should_not_use_equal_implementation_of_root_objects_to_compare() {
    // GIVEN
    AlwaysEqualPerson actual = new AlwaysEqualPerson();
    actual.name = "John";
    actual.home.address.number = 1;
    AlwaysEqualPerson expected = new AlwaysEqualPerson();
    expected.name = "John";
    expected.home.address.number = 2;
    // WHEN
    compareRecursivelyFailsAsExpected(actual, expected);
    // THEN
    ComparisonDifference numberDifference = diff("home.address.number", actual.home.address.number, expected.home.address.number);
    verifyShouldBeEqualByComparingFieldByFieldRecursivelyCall(actual, expected, numberDifference);
}
Also used : AlwaysEqualPerson(org.assertj.core.internal.objects.data.AlwaysEqualPerson) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with AlwaysEqualPerson

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

the class RecursiveComparisonAssert_isEqualTo_ignoringOverriddenEquals_Test method overridden_equals_is_not_used_on_the_object_under_test_itself.

@Test
void overridden_equals_is_not_used_on_the_object_under_test_itself() {
    // GIVEN
    AlwaysEqualPerson actual = new AlwaysEqualPerson();
    actual.name = "John";
    AlwaysEqualPerson expected = new AlwaysEqualPerson();
    expected.name = "Jack";
    // THEN
    // would have succeeded if we had used AlwaysEqualPerson equals method
    compareRecursivelyFailsAsExpected(actual, expected);
}
Also used : AlwaysEqualPerson(org.assertj.core.internal.objects.data.AlwaysEqualPerson) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)

Example 3 with AlwaysEqualPerson

use of org.assertj.core.internal.objects.data.AlwaysEqualPerson 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_regexes.

@Test
void should_fail_when_actual_differs_from_expected_as_some_overridden_equals_methods_are_ignored_by_regexes() {
    // 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.ignoreOverriddenEqualsForFieldsMatchingRegexes(".*AlwaysEqualPerson", ".*AlwaysEqualAddress");
    // 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);
}
Also used : AlwaysEqualPerson(org.assertj.core.internal.objects.data.AlwaysEqualPerson) AlwaysEqualAddress(org.assertj.core.internal.objects.data.AlwaysEqualAddress) Person(org.assertj.core.internal.objects.data.Person) AlwaysDifferentPerson(org.assertj.core.internal.objects.data.AlwaysDifferentPerson) AlwaysEqualPerson(org.assertj.core.internal.objects.data.AlwaysEqualPerson) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)

Example 4 with AlwaysEqualPerson

use of org.assertj.core.internal.objects.data.AlwaysEqualPerson 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);
}
Also used : AlwaysEqualPerson(org.assertj.core.internal.objects.data.AlwaysEqualPerson) AlwaysEqualAddress(org.assertj.core.internal.objects.data.AlwaysEqualAddress) Person(org.assertj.core.internal.objects.data.Person) AlwaysDifferentPerson(org.assertj.core.internal.objects.data.AlwaysDifferentPerson) AlwaysEqualPerson(org.assertj.core.internal.objects.data.AlwaysEqualPerson) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)

Example 5 with AlwaysEqualPerson

use of org.assertj.core.internal.objects.data.AlwaysEqualPerson 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);
}
Also used : AlwaysEqualPerson(org.assertj.core.internal.objects.data.AlwaysEqualPerson) AlwaysEqualAddress(org.assertj.core.internal.objects.data.AlwaysEqualAddress) Person(org.assertj.core.internal.objects.data.Person) AlwaysDifferentPerson(org.assertj.core.internal.objects.data.AlwaysDifferentPerson) AlwaysEqualPerson(org.assertj.core.internal.objects.data.AlwaysEqualPerson) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)

Aggregations

AlwaysEqualPerson (org.assertj.core.internal.objects.data.AlwaysEqualPerson)8 RecursiveComparisonAssert_isEqualTo_BaseTest (org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)7 Test (org.junit.jupiter.api.Test)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Person (org.assertj.core.internal.objects.data.Person)6 AlwaysDifferentPerson (org.assertj.core.internal.objects.data.AlwaysDifferentPerson)4 AlwaysEqualAddress (org.assertj.core.internal.objects.data.AlwaysEqualAddress)3