Search in sources :

Example 21 with Person

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

the class RecursiveComparisonAssert_isEqualTo_withErrorMessageForType_Test method should_be_able_to_set_custom_error_message_for_specific_type.

@Test
void should_be_able_to_set_custom_error_message_for_specific_type() {
    // GIVEN
    Person actual = new Person("Valera");
    actual.age = OptionalInt.of(15);
    Person expected = new Person("John");
    expected.age = OptionalInt.of(15);
    String message = "Name must be the same";
    Class<String> type = String.class;
    // WHEN
    AssertionError assertionError = expectAssertionError(() -> assertThat(actual).usingRecursiveComparison().withErrorMessageForType(message, type).isEqualTo(expected));
    // THEN
    then(assertionError).hasMessageContainingAll(message, ERROR_MESSAGE_DESCRIPTION_FOR_TYPE, "- " + type.getName());
}
Also used : AssertionsUtil.expectAssertionError(org.assertj.core.util.AssertionsUtil.expectAssertionError) Person(org.assertj.core.internal.objects.data.Person) Test(org.junit.jupiter.api.Test) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)

Example 22 with Person

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

the class RecursiveComparisonAssert_assumptions_Test method should_ignore_test_when_one_of_the_assumption_fails.

@Test
void should_ignore_test_when_one_of_the_assumption_fails() {
    // GIVEN
    Person actual = new Person("John");
    actual.home.address.number = 1;
    Person expected = new Person("John");
    expected.home.address.number = 1;
    Person unexpected = new Person("John");
    unexpected.home.address.number = 2;
    // THEN
    assumeThat(actual).usingRecursiveComparison().isEqualTo(expected);
    expectAssumptionNotMetException(() -> assumeThat(actual).usingRecursiveComparison().isEqualTo(unexpected));
}
Also used : Person(org.assertj.core.internal.objects.data.Person) Test(org.junit.jupiter.api.Test) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)

Example 23 with Person

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

the class RecursiveComparisonAssert_isEqualTo_withErrorMessageForFields_Test method should_be_able_to_set_custom_error_message_for_specific_fields.

@Test
void should_be_able_to_set_custom_error_message_for_specific_fields() {
    // GIVEN
    Person actual = new Person("Valera");
    actual.age = OptionalInt.of(15);
    Person expected = new Person("John");
    expected.age = OptionalInt.of(16);
    String message = "Name must be the same";
    String field = "name";
    // WHEN
    AssertionError assertionError = expectAssertionError(() -> assertThat(actual).usingRecursiveComparison().withErrorMessageForFields(message, field).isEqualTo(expected));
    // THEN
    then(assertionError).hasMessageContainingAll(message, ERROR_MESSAGE_DESCRIPTION_FOR_FIELDS, "- " + field);
}
Also used : AssertionsUtil.expectAssertionError(org.assertj.core.util.AssertionsUtil.expectAssertionError) Person(org.assertj.core.internal.objects.data.Person) Test(org.junit.jupiter.api.Test) RecursiveComparisonAssert_isEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_BaseTest)

Example 24 with Person

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

the class RecursiveComparisonAssert_isNotEqualTo_Test method should_pass_when_either_actual_or_expected_is_null.

@Test
void should_pass_when_either_actual_or_expected_is_null() {
    // GIVEN
    Person actual = null;
    Person other = new Person();
    // THEN
    assertThat(actual).usingRecursiveComparison().isNotEqualTo(other);
    assertThat(other).usingRecursiveComparison().isNotEqualTo(actual);
}
Also used : Person(org.assertj.core.internal.objects.data.Person) Test(org.junit.jupiter.api.Test) RecursiveComparisonAssert_isNotEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isNotEqualTo_BaseTest)

Example 25 with Person

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

the class RecursiveComparisonAssert_isNotEqualTo_Test method should_be_able_to_compare_objects_of_different_types.

@Test
void should_be_able_to_compare_objects_of_different_types() {
    // GIVEN
    CartoonCharacter other = new CartoonCharacter("Homer Simpson");
    Person actual = new Person("Homer Simpson");
    // THEN not equal because of children field in CartoonCharacter
    assertThat(actual).usingRecursiveComparison().isNotEqualTo(other);
}
Also used : CartoonCharacter(org.assertj.core.test.CartoonCharacter) Person(org.assertj.core.internal.objects.data.Person) Test(org.junit.jupiter.api.Test) RecursiveComparisonAssert_isNotEqualTo_BaseTest(org.assertj.core.api.RecursiveComparisonAssert_isNotEqualTo_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