Search in sources :

Example 6 with Person

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

the class RecursiveComparisonAssert_isEqualTo_Test method should_fail_when_fields_of_different_nesting_levels_differ.

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

Example 7 with Person

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

the class RecursiveComparisonAssert_isEqualTo_comparingOnlyFields_Test method should_fail_when_actual_differs_from_expected_on_compared_fields.

@Test
void should_fail_when_actual_differs_from_expected_on_compared_fields() {
    // GIVEN
    Person actual = new Person("John");
    actual.home.address.number = 1;
    actual.dateOfBirth = new Date(123);
    actual.neighbour = new Person("Jim");
    actual.neighbour.home.address.number = 123;
    actual.neighbour.neighbour = new Person("James");
    actual.neighbour.neighbour.home.address.number = 124;
    Person expected = new Person("John");
    expected.home.address.number = 1;
    expected.dateOfBirth = new Date(456);
    expected.neighbour = new Person("Jack");
    expected.neighbour.home.address.number = 123;
    expected.neighbour.neighbour = new Person("James");
    expected.neighbour.neighbour.home.address.number = 125;
    recursiveComparisonConfiguration.compareOnlyFields("name", "home", "dateOfBirth", "neighbour");
    // WHEN
    compareRecursivelyFailsAsExpected(actual, expected);
    // THEN
    ComparisonDifference dateOfBirthDifference = diff("dateOfBirth", actual.dateOfBirth, expected.dateOfBirth);
    ComparisonDifference neighbourNameDifference = diff("neighbour.name", actual.neighbour.name, expected.neighbour.name);
    ComparisonDifference numberDifference = diff("neighbour.neighbour.home.address.number", actual.neighbour.neighbour.home.address.number, expected.neighbour.neighbour.home.address.number);
    verifyShouldBeEqualByComparingFieldByFieldRecursivelyCall(actual, expected, dateOfBirthDifference, neighbourNameDifference, numberDifference);
}
Also used : Person(org.assertj.core.internal.objects.data.Person) Date(java.util.Date) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)

Example 8 with Person

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

the class RecursiveComparisonAssert_isEqualTo_comparingOnlyFields_Test method should_only_compare_given_fields.

private static Stream<Arguments> should_only_compare_given_fields() {
    Person person1 = new Person("John");
    person1.home.address.number = 1;
    Person person2 = new Person("John");
    person2.home.address.number = 2;
    Person john = new Person("John");
    john.home.address.number = 1;
    john.dateOfBirth = new Date(123);
    john.neighbour = new Person("Jim");
    john.neighbour.home.address.number = 123;
    john.neighbour.neighbour = new Person("James");
    john.neighbour.neighbour.home.address.number = 124;
    Person jack = new Person("Jack");
    jack.home.address.number = 1;
    jack.dateOfBirth = new Date(456);
    jack.neighbour = new Person("Jack");
    jack.neighbour.home.address.number = 456;
    jack.neighbour.neighbour = new Person("James");
    jack.neighbour.neighbour.home.address.number = 124;
    Human person4 = new Human();
    person4.name = "John";
    person4.home.address.number = 1;
    Human person5 = new Human();
    person5.home.address.number = 1;
    return Stream.of(arguments(person1, person2, list("name")), arguments(person1, person4, list("name")), arguments(person1, person5, list("home")), arguments(person1, person5, list("home.address")), arguments(person1, person5, list("home.address.number")), arguments(john, jack, list("home", "neighbour.neighbour")), arguments(john, jack, list("home.address", "neighbour.neighbour")), arguments(john, jack, list("home.address.number", "neighbour.neighbour")), arguments(john, jack, list("home", "neighbour.neighbour.home")), arguments(john, jack, list("home.address", "neighbour.neighbour")));
}
Also used : Human(org.assertj.core.internal.objects.data.Human) Person(org.assertj.core.internal.objects.data.Person) Date(java.util.Date)

Example 9 with Person

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

the class RecursiveComparisonAssert_isEqualTo_ignoringFields_Test method should_fail_when_actual_differs_from_expected_even_when_some_fields_are_ignored.

@Test
void should_fail_when_actual_differs_from_expected_even_when_some_fields_are_ignored() {
    // 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;
    actual.neighbour.neighbour = new Person("James");
    actual.neighbour.neighbour.home.address.number = 124;
    Person expected = new Person("Jack");
    expected.home.address.number = 2;
    expected.dateOfBirth = new Date(456);
    expected.neighbour = new Person("Jim");
    expected.neighbour.home.address.number = 123;
    expected.neighbour.neighbour = new Person("James");
    expected.neighbour.neighbour.home.address.number = 457;
    recursiveComparisonConfiguration.ignoreFields("name", "home.address.number");
    // WHEN
    compareRecursivelyFailsAsExpected(actual, expected);
    // THEN
    ComparisonDifference dateOfBirthDifference = diff("dateOfBirth", actual.dateOfBirth, expected.dateOfBirth);
    ComparisonDifference neighbourNameDifference = diff("neighbour.name", actual.neighbour.name, expected.neighbour.name);
    ComparisonDifference numberDifference = diff("neighbour.neighbour.home.address.number", actual.neighbour.neighbour.home.address.number, expected.neighbour.neighbour.home.address.number);
    verifyShouldBeEqualByComparingFieldByFieldRecursivelyCall(actual, expected, dateOfBirthDifference, neighbourNameDifference, numberDifference);
}
Also used : Person(org.assertj.core.internal.objects.data.Person) Date(java.util.Date) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)

Example 10 with Person

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

the class RecursiveComparisonAssert_isEqualTo_ignoringFields_Test method should_fail_when_actual_differs_from_expected_even_when_some_fields_are_ignored_for_types.

@Test
void should_fail_when_actual_differs_from_expected_even_when_some_fields_are_ignored_for_types() {
    // GIVEN
    Person actual = new Person("John");
    actual.home.address = null;
    actual.neighbour = new Person("Jack");
    actual.neighbour.home.address.number = 123;
    actual.neighbour.neighbour = new Person("James");
    actual.neighbour.neighbour.dateOfBirth = new Date(123);
    Person expected = new Person("Jack");
    expected.home.address.number = 2;
    expected.neighbour = new Person("Jim");
    expected.neighbour.home.address.number = 456;
    expected.neighbour.neighbour = new Person("James");
    expected.neighbour.neighbour.dateOfBirth = new Date(456);
    recursiveComparisonConfiguration.ignoreFieldsOfTypes(String.class, Address.class);
    // WHEN
    compareRecursivelyFailsAsExpected(actual, expected);
    // THEN
    ComparisonDifference addressDifference = diff("home.address", actual.home.address, expected.home.address);
    ComparisonDifference neighbourDateOfBirthDifference = diff("neighbour.neighbour.dateOfBirth", actual.neighbour.neighbour.dateOfBirth, expected.neighbour.neighbour.dateOfBirth);
    verifyShouldBeEqualByComparingFieldByFieldRecursivelyCall(actual, expected, addressDifference, neighbourDateOfBirthDifference);
}
Also used : Person(org.assertj.core.internal.objects.data.Person) Date(java.util.Date) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)

Aggregations

Person (org.assertj.core.internal.objects.data.Person)62 Test (org.junit.jupiter.api.Test)46 RecursiveComparisonAssert_isEqualTo_BaseTest (org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)38 AlwaysEqualPerson (org.assertj.core.internal.objects.data.AlwaysEqualPerson)27 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 Date (java.util.Date)20 AlwaysDifferentPerson (org.assertj.core.internal.objects.data.AlwaysDifferentPerson)9 FriendlyPerson (org.assertj.core.internal.objects.data.FriendlyPerson)9 Human (org.assertj.core.internal.objects.data.Human)6 RecursiveComparisonAssert_isNotEqualTo_BaseTest (org.assertj.core.api.RecursiveComparisonAssert_isNotEqualTo_BaseTest)5 AlwaysDifferentAddress (org.assertj.core.internal.objects.data.AlwaysDifferentAddress)4 Timestamp (java.sql.Timestamp)3 AlwaysEqualAddress (org.assertj.core.internal.objects.data.AlwaysEqualAddress)3 Giant (org.assertj.core.internal.objects.data.Giant)3 AssertionsUtil.expectAssertionError (org.assertj.core.util.AssertionsUtil.expectAssertionError)3 PersonDto (org.assertj.core.internal.objects.data.PersonDto)2 CartoonCharacter (org.assertj.core.test.CartoonCharacter)2 Comparator (java.util.Comparator)1 AtPrecisionComparator (org.assertj.core.internal.AtPrecisionComparator)1 CaseInsensitiveStringComparator (org.assertj.core.internal.CaseInsensitiveStringComparator)1