use of org.assertj.core.internal.DeepDifference.Difference in project assertj-core by joel-costigliola.
the class ShouldBeEqualByComparingFieldByFieldRecursively_create_Test method should_precise_missing_fields_when_actual_does_not_declare_all_expected_fields.
@Test
public void should_precise_missing_fields_when_actual_does_not_declare_all_expected_fields() {
// GIVEN
Person person = new Person("John", "Doe");
PersonDAO personDAO = new PersonDAO("John", "Doe", 1L, 23);
// THEN
List<Difference> differences = determineDifferences(person, personDAO, null, null);
// WHEN
// @format:off
String message = shouldBeEqualByComparingFieldByFieldRecursive(person, personDAO, differences, REPRESENTATION).create(new TextDescription("Test"), REPRESENTATION);
// @format:on
// THEN
String personHash = toHexString(person.hashCode());
String personDAOHash = toHexString(personDAO.hashCode());
assertThat(message).isEqualTo(format("[Test] %n" + "Expecting:%n" + " <org.assertj.core.error.Person@%s>%n" + "to be equal to:%n" + " <org.assertj.core.error.PersonDAO@%s>%n" + "when recursively comparing field by field, but found the following difference(s):%n" + "%n" + "Path to difference: <>%n" + "- actual : <org.assertj.core.error.Person@%s>%n" + "- expected: <org.assertj.core.error.PersonDAO@%s>%n" + "- reason : org.assertj.core.error.Person can't be compared to org.assertj.core.error.PersonDAO as PersonDAO does not declare all Person fields, it lacks these:[firstName, lastName]", personHash, personDAOHash, personHash, personDAOHash));
}
use of org.assertj.core.internal.DeepDifference.Difference in project assertj-core by joel-costigliola.
the class Objects_assertIsEqualToComparingFieldByFieldRecursive_Test method should_not_use_equal_implementation_of_objects_to_compare.
@Test
public void should_not_use_equal_implementation_of_objects_to_compare() {
AssertionInfo info = someInfo();
EqualPerson actual = new EqualPerson();
actual.name = "John";
actual.home.address.number = 1;
EqualPerson other = new EqualPerson();
other.name = "John";
other.home.address.number = 2;
try {
objects.assertIsEqualToComparingFieldByFieldRecursively(info, actual, other, noFieldComparators(), defaultTypeComparators());
} catch (AssertionError err) {
verify(failures).failure(info, shouldBeEqualByComparingFieldByFieldRecursive(actual, other, asList(new Difference(asList("home.address.number"), 1, 2)), CONFIGURATION_PROVIDER.representation()));
return;
}
failBecauseExpectedAssertionErrorWasNotThrown();
}
use of org.assertj.core.internal.DeepDifference.Difference in project assertj-core by joel-costigliola.
the class Objects_assertIsEqualToComparingFieldByFieldRecursive_Test method should_fail_when_fields_differ.
@Test
public void should_fail_when_fields_differ() {
AssertionInfo info = someInfo();
Person actual = new Person();
actual.name = "John";
Person other = new Person();
other.name = "Jack";
try {
objects.assertIsEqualToComparingFieldByFieldRecursively(info, actual, other, noFieldComparators(), defaultTypeComparators());
} catch (AssertionError err) {
verify(failures).failure(info, shouldBeEqualByComparingFieldByFieldRecursive(actual, other, asList(new Difference(asList("name"), "John", "Jack")), CONFIGURATION_PROVIDER.representation()));
return;
}
failBecauseExpectedAssertionErrorWasNotThrown();
}
use of org.assertj.core.internal.DeepDifference.Difference in project assertj-core by joel-costigliola.
the class Objects_assertIsEqualToComparingFieldByFieldRecursive_Test method should_fail_when_fields_of_child_objects_differ.
@Test
public void should_fail_when_fields_of_child_objects_differ() {
AssertionInfo info = someInfo();
Person actual = new Person();
actual.name = "John";
actual.home.address.number = 1;
Person other = new Person();
other.name = "John";
other.home.address.number = 2;
try {
objects.assertIsEqualToComparingFieldByFieldRecursively(info, actual, other, noFieldComparators(), defaultTypeComparators());
} catch (AssertionError err) {
verify(failures).failure(info, shouldBeEqualByComparingFieldByFieldRecursive(actual, other, asList(new Difference(asList("home.address.number"), 1, 2)), CONFIGURATION_PROVIDER.representation()));
return;
}
failBecauseExpectedAssertionErrorWasNotThrown();
}
use of org.assertj.core.internal.DeepDifference.Difference in project assertj-core by joel-costigliola.
the class ShouldBeEqualByComparingFieldByFieldRecursively_create_Test method should_use_unambiguous_fields_description_when_standard_description_of_actual_and_expected_map_fields_values_are_identical.
@Test
public void should_use_unambiguous_fields_description_when_standard_description_of_actual_and_expected_map_fields_values_are_identical() {
// GIVEN
WithMap<Long, Boolean> withLinkedHashMap = new WithMap<>(new LinkedHashMap<Long, Boolean>());
WithMap<Long, Boolean> withTreeMap = new WithMap<>(new TreeMap<Long, Boolean>());
withLinkedHashMap.map.put(1L, true);
withLinkedHashMap.map.put(2L, false);
withTreeMap.map.putAll(withLinkedHashMap.map);
List<Difference> differences = determineDifferences(withLinkedHashMap, withTreeMap, null, null);
// WHEN
// @format:off
String message = shouldBeEqualByComparingFieldByFieldRecursive(withTreeMap, withLinkedHashMap, differences, REPRESENTATION).create(new TextDescription("Test"), REPRESENTATION);
// @format:on
// THEN
assertThat(message).isEqualTo(format("[Test] %n" + "Expecting:%n" + " <WithMap [map={1=true, 2=false}]>%n" + "to be equal to:%n" + " <WithMap [map={1=true, 2=false}]>%n" + "when recursively comparing field by field, but found the following difference(s):%n" + "%n" + "Path to difference: <map>%n" + "- actual : <{1L=true, 2L=false} (LinkedHashMap@%s)>%n" + "- expected: <{1L=true, 2L=false} (TreeMap@%s)>", toHexString(withTreeMap.map.hashCode()), toHexString(withLinkedHashMap.map.hashCode())));
}
Aggregations