Search in sources :

Example 1 with AtPrecisionComparator

use of org.assertj.core.internal.AtPrecisionComparator 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 2 with AtPrecisionComparator

use of org.assertj.core.internal.AtPrecisionComparator 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 3 with AtPrecisionComparator

use of org.assertj.core.internal.AtPrecisionComparator in project assertj-core by joel-costigliola.

the class RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test method should_be_able_to_compare_objects_recursively_using_some_precision_for_numerical_fields.

@Test
void should_be_able_to_compare_objects_recursively_using_some_precision_for_numerical_fields() {
    // GIVEN
    Giant goliath = new Giant();
    goliath.name = "Goliath";
    goliath.height = 3.0;
    Giant goliathTwin = new Giant();
    goliathTwin.name = "Goliath";
    goliathTwin.height = 3.1;
    // THEN
    then(goliath).usingRecursiveComparison().withComparatorForFields(new AtPrecisionComparator<>(0.2), "height").isEqualTo(goliathTwin);
    then(goliath).usingRecursiveComparison().withEqualsForFields((Double d1, Double d2) -> Math.abs(d1 - d2) <= 0.2, "height").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)

Aggregations

RecursiveComparisonAssert_isEqualTo_BaseTest (org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)3 AtPrecisionComparator (org.assertj.core.internal.AtPrecisionComparator)3 Giant (org.assertj.core.internal.objects.data.Giant)3 Test (org.junit.jupiter.api.Test)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Timestamp (java.sql.Timestamp)1 Comparator (java.util.Comparator)1 Date (java.util.Date)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 AlwaysEqualPerson (org.assertj.core.internal.objects.data.AlwaysEqualPerson)1 Person (org.assertj.core.internal.objects.data.Person)1