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