Search in sources :

Example 1 with Giant

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

the class RecursiveComparisonAssert_isEqualTo_Test method should_report_missing_property.

@Test
void should_report_missing_property() {
    // GIVEN
    Giant actual = new Giant();
    actual.name = "joe";
    actual.height = 3.0;
    Human expected = new Human();
    expected.name = "joe";
    // WHEN
    compareRecursivelyFailsAsExpected(actual, expected);
    // THEN
    ComparisonDifference missingFieldDifference = diff("", actual, expected, "org.assertj.core.internal.objects.data.Giant can't be compared to org.assertj.core.internal.objects.data.Human as Human does not declare all Giant fields, it lacks these: [height]");
    verifyShouldBeEqualByComparingFieldByFieldRecursivelyCall(actual, expected, missingFieldDifference);
}
Also used : Human(org.assertj.core.internal.objects.data.Human) Giant(org.assertj.core.internal.objects.data.Giant) 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 Giant

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

the class RecursiveComparisonAssert_isEqualTo_ignoringFields_Test method recursivelyEqualObjectsWhenFieldsMatchingGivenRegexesAreIgnored.

private static Stream<Arguments> recursivelyEqualObjectsWhenFieldsMatchingGivenRegexesAreIgnored() {
    Person person1 = new Person("John");
    person1.home.address.number = 1;
    Person giant1 = new Giant();
    giant1.name = "Giant John";
    ((Giant) giant1).height = 3.1;
    giant1.home.address.number = 1;
    Person person2 = new Person("Jack");
    person2.home.address.number = 1;
    Person person3 = new Person("John");
    person3.home.address.number = 123;
    Human person4 = new Human();
    person4.name = "Jack";
    person4.home.address.number = 456;
    Person person5 = new Person();
    person5.home.address.number = 1;
    Person person6 = new Person();
    person6.home.address.number = 2;
    Person person7 = new Person("John");
    person7.neighbour = new Person("Jack");
    person7.neighbour.home.address.number = 123;
    person7.neighbour.neighbour = new Person("James");
    person7.neighbour.neighbour.home.address.number = 124;
    Person person8 = new Person("John");
    person8.neighbour = new Person("Jim");
    person8.neighbour.home.address.number = 123;
    person8.neighbour.neighbour = new Person("James");
    person8.neighbour.neighbour.home.address.number = 457;
    // @format:off
    return Stream.of(arguments(person1, person2, "same data and type, except for one ignored field", list("nam.")), arguments(giant1, person1, "different type, same data except name and height which is not even a field from person1", list(".am.", "height")), arguments(person3, person4, "same data, different type, except for name and home.address.number", list(".*n.m.*")), arguments(person5, person6, "same data except for one subfield of an ignored field", list("home.*")), arguments(person7, person8, "same data except for one subfield of an ignored field", list("neighbour.*")), arguments(person7, person8, "should not stack overflow with regexes", list(".*neighbour[\\D]+", ".*update[\\D]+")));
// @format:on
}
Also used : Human(org.assertj.core.internal.objects.data.Human) Giant(org.assertj.core.internal.objects.data.Giant) Person(org.assertj.core.internal.objects.data.Person)

Example 3 with Giant

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

the class RecursiveComparisonAssert_isEqualTo_withTypeComparators_Test method should_be_able_to_compare_objects_recursively_using_some_precision_for_numerical_types.

@Test
void should_be_able_to_compare_objects_recursively_using_some_precision_for_numerical_types() {
    // GIVEN
    Giant goliath = new Giant();
    goliath.name = "Goliath";
    goliath.height = 3.0;
    Giant goliathTwin = new Giant();
    goliathTwin.name = "Goliath";
    goliathTwin.height = 3.1;
    // THEN
    assertThat(goliath).usingRecursiveComparison().withComparatorForType(new AtPrecisionComparator<>(0.2), Double.class).isEqualTo(goliathTwin);
    assertThat(goliath).usingRecursiveComparison().withEqualsForType((d1, d2) -> Math.abs(d1 - d2) < 0.2, Double.class).isEqualTo(goliathTwin);
}
Also used : Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ALWAYS_EQUALS_TIMESTAMP(org.assertj.core.test.AlwaysEqualComparator.ALWAYS_EQUALS_TIMESTAMP) Person(org.assertj.core.internal.objects.data.Person) BiPredicate(java.util.function.BiPredicate) SYMMETRIC_DATE_COMPARATOR(org.assertj.core.internal.objects.SymmetricDateComparator.SYMMETRIC_DATE_COMPARATOR) CaseInsensitiveStringComparator(org.assertj.core.internal.CaseInsensitiveStringComparator) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest) Map(java.util.Map) Maps.mapOf(org.assertj.core.test.Maps.mapOf) AlwaysEqualPerson(org.assertj.core.internal.objects.data.AlwaysEqualPerson) Address(org.assertj.core.internal.objects.data.Address) Arguments.arguments(org.junit.jupiter.params.provider.Arguments.arguments) MethodSource(org.junit.jupiter.params.provider.MethodSource) NEVER_EQUALS(org.assertj.core.test.NeverEqualComparator.NEVER_EQUALS) Timestamp(java.sql.Timestamp) BDDAssertions.then(org.assertj.core.api.BDDAssertions.then) AlwaysEqualComparator(org.assertj.core.test.AlwaysEqualComparator) Arguments(org.junit.jupiter.params.provider.Arguments) Assertions.entry(org.assertj.core.api.Assertions.entry) AssertionsUtil.expectAssertionError(org.assertj.core.util.AssertionsUtil.expectAssertionError) MapEntry(org.assertj.core.data.MapEntry) AlwaysDifferentComparator(org.assertj.core.test.AlwaysDifferentComparator) Test(org.junit.jupiter.api.Test) Giant(org.assertj.core.internal.objects.data.Giant) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) Patient(org.assertj.core.test.Patient) AtPrecisionComparator(org.assertj.core.internal.AtPrecisionComparator) ALWAYS_EQUALS(org.assertj.core.test.AlwaysEqualComparator.ALWAYS_EQUALS) Comparator(java.util.Comparator) AtPrecisionComparator(org.assertj.core.internal.AtPrecisionComparator) Giant(org.assertj.core.internal.objects.data.Giant) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Giant

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

the class RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test method should_be_able_to_compare_objects_recursively_using_given_comparator_for_specified_nested_field.

@Test
void should_be_able_to_compare_objects_recursively_using_given_comparator_for_specified_nested_field() {
    // GIVEN
    Giant goliath = new Giant();
    goliath.name = "Goliath";
    goliath.height = 3.0;
    goliath.home.address.number = 1;
    Giant goliathTwin = new Giant();
    goliathTwin.name = "Goliath";
    goliathTwin.height = 3.1;
    goliathTwin.home.address.number = 5;
    // THEN
    then(goliath).usingRecursiveComparison().withComparatorForFields(new AtPrecisionComparator<>(0.2), "height").withComparatorForFields(new AtPrecisionComparator<>(10), "home.address.number").isEqualTo(goliathTwin);
}
Also used : AtPrecisionComparator(org.assertj.core.internal.AtPrecisionComparator) Giant(org.assertj.core.internal.objects.data.Giant) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with Giant

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

the class RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test method should_be_able_to_compare_objects_recursively_using_given_BiPredicate_for_specified_nested_field.

@Test
void should_be_able_to_compare_objects_recursively_using_given_BiPredicate_for_specified_nested_field() {
    // GIVEN
    Giant goliath = new Giant();
    goliath.name = "Goliath";
    goliath.height = 3.0;
    goliath.home.address.number = 1;
    Giant goliathTwin = new Giant();
    goliathTwin.name = "Goliath";
    goliathTwin.height = 3.1;
    goliathTwin.home.address.number = 5;
    // THEN
    then(goliath).usingRecursiveComparison().withEqualsForFields((Double d1, Double d2) -> Math.abs(d1 - d2) <= 0.2, "height").withEqualsForFields((Integer i1, Integer i2) -> Math.abs(i1 - i2) <= 10, "home.address.number").isEqualTo(goliathTwin);
}
Also used : Giant(org.assertj.core.internal.objects.data.Giant) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Giant (org.assertj.core.internal.objects.data.Giant)8 RecursiveComparisonAssert_isEqualTo_BaseTest (org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)6 Test (org.junit.jupiter.api.Test)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Person (org.assertj.core.internal.objects.data.Person)4 AtPrecisionComparator (org.assertj.core.internal.AtPrecisionComparator)3 Human (org.assertj.core.internal.objects.data.Human)3 Date (java.util.Date)2 Timestamp (java.sql.Timestamp)1 Comparator (java.util.Comparator)1 Map (java.util.Map)1 BiPredicate (java.util.function.BiPredicate)1 Stream (java.util.stream.Stream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.entry (org.assertj.core.api.Assertions.entry)1 BDDAssertions.then (org.assertj.core.api.BDDAssertions.then)1 MapEntry (org.assertj.core.data.MapEntry)1 CaseInsensitiveStringComparator (org.assertj.core.internal.CaseInsensitiveStringComparator)1 SYMMETRIC_DATE_COMPARATOR (org.assertj.core.internal.objects.SymmetricDateComparator.SYMMETRIC_DATE_COMPARATOR)1 Address (org.assertj.core.internal.objects.data.Address)1