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);
}
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
}
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);
}
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);
}
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);
}
Aggregations