Search in sources :

Example 1 with ALWAYS_EQUALS_TIMESTAMP

use of org.assertj.core.test.AlwaysEqualComparator.ALWAYS_EQUALS_TIMESTAMP in project assertj-core by joel-costigliola.

the class RecursiveComparisonAssert_isEqualTo_withTypeComparators_Test method should_handle_null_field_with_type_comparator.

@Test
void should_handle_null_field_with_type_comparator() {
    // GIVEN
    Patient actual = new Patient(null);
    Patient expected = new Patient(new Timestamp(3L));
    // THEN
    assertThat(actual).usingRecursiveComparison().withComparatorForType(ALWAYS_EQUALS_TIMESTAMP, Timestamp.class).isEqualTo(expected);
    assertThat(actual).usingRecursiveComparison().withEqualsForType((o1, o2) -> true, Timestamp.class).isEqualTo(expected);
}
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) Patient(org.assertj.core.test.Patient) Timestamp(java.sql.Timestamp) 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 ALWAYS_EQUALS_TIMESTAMP

use of org.assertj.core.test.AlwaysEqualComparator.ALWAYS_EQUALS_TIMESTAMP in project assertj-core by joel-costigliola.

the class RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test method should_handle_null_field_with_field_comparator.

@Test
void should_handle_null_field_with_field_comparator() {
    // GIVEN
    Patient actual = new Patient(null);
    Patient expected = new Patient(new Timestamp(3L));
    // THEN
    then(actual).usingRecursiveComparison().withComparatorForFields(ALWAYS_EQUALS_TIMESTAMP, "dateOfBirth").isEqualTo(expected);
    then(actual).usingRecursiveComparison().withEqualsForFields((o1, o2) -> true, "dateOfBirth").isEqualTo(expected);
}
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) AlwaysEqualPerson(org.assertj.core.internal.objects.data.AlwaysEqualPerson) 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) AlwaysDifferentComparator.alwaysDifferent(org.assertj.core.test.AlwaysDifferentComparator.alwaysDifferent) BDDAssertions.then(org.assertj.core.api.BDDAssertions.then) Arguments(org.junit.jupiter.params.provider.Arguments) Arrays.array(org.assertj.core.util.Arrays.array) AssertionsUtil.expectAssertionError(org.assertj.core.util.AssertionsUtil.expectAssertionError) Objects(java.util.Objects) 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) AlwaysEqualComparator.alwaysEqual(org.assertj.core.test.AlwaysEqualComparator.alwaysEqual) Patient(org.assertj.core.test.Patient) Timestamp(java.sql.Timestamp) 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 ALWAYS_EQUALS_TIMESTAMP

use of org.assertj.core.test.AlwaysEqualComparator.ALWAYS_EQUALS_TIMESTAMP in project assertj-core by joel-costigliola.

the class RecursiveComparisonAssert_isEqualTo_withFieldComparators_Test method field_comparator_should_take_precedence_over_type_comparator_whatever_their_order_of_registration.

@Test
void field_comparator_should_take_precedence_over_type_comparator_whatever_their_order_of_registration() {
    // GIVEN
    Patient actual = new Patient(new Timestamp(1L));
    Patient expected = new Patient(new Timestamp(3L));
    // THEN
    then(actual).usingRecursiveComparison().withComparatorForType(NEVER_EQUALS, Timestamp.class).withComparatorForFields(ALWAYS_EQUALS_TIMESTAMP, "dateOfBirth").isEqualTo(expected);
    then(actual).usingRecursiveComparison().withComparatorForFields(ALWAYS_EQUALS_TIMESTAMP, "dateOfBirth").withComparatorForType(NEVER_EQUALS, Timestamp.class).isEqualTo(expected);
    then(actual).usingRecursiveComparison().withEqualsForType((o1, o2) -> false, Timestamp.class).withEqualsForFields((o1, o2) -> true, "dateOfBirth").isEqualTo(expected);
    then(actual).usingRecursiveComparison().withEqualsForFields((o1, o2) -> true, "dateOfBirth").withEqualsForType((o1, o2) -> false, Timestamp.class).isEqualTo(expected);
}
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) AlwaysEqualPerson(org.assertj.core.internal.objects.data.AlwaysEqualPerson) 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) AlwaysDifferentComparator.alwaysDifferent(org.assertj.core.test.AlwaysDifferentComparator.alwaysDifferent) BDDAssertions.then(org.assertj.core.api.BDDAssertions.then) Arguments(org.junit.jupiter.params.provider.Arguments) Arrays.array(org.assertj.core.util.Arrays.array) AssertionsUtil.expectAssertionError(org.assertj.core.util.AssertionsUtil.expectAssertionError) Objects(java.util.Objects) 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) AlwaysEqualComparator.alwaysEqual(org.assertj.core.test.AlwaysEqualComparator.alwaysEqual) Patient(org.assertj.core.test.Patient) Timestamp(java.sql.Timestamp) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Timestamp (java.sql.Timestamp)3 Comparator (java.util.Comparator)3 Date (java.util.Date)3 BiPredicate (java.util.function.BiPredicate)3 Stream (java.util.stream.Stream)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 BDDAssertions.then (org.assertj.core.api.BDDAssertions.then)3 RecursiveComparisonAssert_isEqualTo_BaseTest (org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)3 AtPrecisionComparator (org.assertj.core.internal.AtPrecisionComparator)3 CaseInsensitiveStringComparator (org.assertj.core.internal.CaseInsensitiveStringComparator)3 SYMMETRIC_DATE_COMPARATOR (org.assertj.core.internal.objects.SymmetricDateComparator.SYMMETRIC_DATE_COMPARATOR)3 AlwaysEqualPerson (org.assertj.core.internal.objects.data.AlwaysEqualPerson)3 Giant (org.assertj.core.internal.objects.data.Giant)3 Person (org.assertj.core.internal.objects.data.Person)3 ALWAYS_EQUALS (org.assertj.core.test.AlwaysEqualComparator.ALWAYS_EQUALS)3 ALWAYS_EQUALS_TIMESTAMP (org.assertj.core.test.AlwaysEqualComparator.ALWAYS_EQUALS_TIMESTAMP)3 NEVER_EQUALS (org.assertj.core.test.NeverEqualComparator.NEVER_EQUALS)3 Patient (org.assertj.core.test.Patient)3 AssertionsUtil.expectAssertionError (org.assertj.core.util.AssertionsUtil.expectAssertionError)3 Test (org.junit.jupiter.api.Test)3