How to use Objects_assertIsEqualToComparingFieldByFieldRecursive_Test class of org.assertj.core.internal.objects package

Best Assertj code snippet using org.assertj.core.internal.objects.Objects_assertIsEqualToComparingFieldByFieldRecursive_Test

Source:Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.java Github

copy

Full Screen

...37import org.assertj.core.test.TestData;38import org.assertj.core.test.TestFailures;39import org.junit.jupiter.api.Test;40import org.mockito.Mockito;41public class Objects_assertIsEqualToComparingFieldByFieldRecursive_Test extends ObjectsBaseTest {42 @Test43 public void should_be_able_to_compare_objects_recursively() {44 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();45 actual.name = "John";46 actual.home.address.number = 1;47 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person other = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();48 other.name = "John";49 other.home.address.number = 1;50 objects.assertIsEqualToComparingFieldByFieldRecursively(TestData.someInfo(), actual, other, ObjectsBaseTest.noFieldComparators(), TypeComparators.defaultTypeComparators());51 }52 @Test53 public void should_be_able_to_compare_objects_of_different_types_recursively() {54 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();55 actual.name = "John";56 actual.home.address.number = 1;57 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Human other = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Human();58 other.name = "John";59 other.home.address.number = 1;60 objects.assertIsEqualToComparingFieldByFieldRecursively(TestData.someInfo(), actual, other, ObjectsBaseTest.noFieldComparators(), TypeComparators.defaultTypeComparators());61 }62 @Test63 public void should_be_able_to_compare_objects_recursively_using_some_precision_for_numerical_types() {64 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant goliath = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant();65 goliath.name = "Goliath";66 goliath.height = 3.0;67 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant goliathTwin = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant();68 goliathTwin.name = "Goliath";69 goliathTwin.height = 3.1;70 Assertions.assertThat(goliath).usingComparatorForType(new AtPrecisionComparator(0.2), Double.class).isEqualToComparingFieldByFieldRecursively(goliathTwin);71 }72 @Test73 public void should_be_able_to_compare_objects_recursively_using_given_comparator_for_specified_field() {74 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant goliath = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant();75 goliath.name = "Goliath";76 goliath.height = 3.0;77 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant goliathTwin = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant();78 goliathTwin.name = "Goliath";79 goliathTwin.height = 3.1;80 Assertions.assertThat(goliath).usingComparatorForFields(new AtPrecisionComparator(0.2), "height").isEqualToComparingFieldByFieldRecursively(goliathTwin);81 }82 @Test83 public void should_be_able_to_compare_objects_recursively_using_given_comparator_for_specified_nested_field() {84 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant goliath = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant();85 goliath.name = "Goliath";86 goliath.height = 3.0;87 goliath.home.address.number = 1;88 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant goliathTwin = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant();89 goliathTwin.name = "Goliath";90 goliathTwin.height = 3.1;91 goliathTwin.home.address.number = 5;92 Assertions.assertThat(goliath).usingComparatorForFields(new AtPrecisionComparator(0.2), "height").usingComparatorForFields(new AtPrecisionComparator(10), "home.address.number").isEqualToComparingFieldByFieldRecursively(goliathTwin);93 }94 @Test95 public void should_be_able_to_compare_objects_with_cycles_recursively() {96 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson();97 actual.name = "John";98 actual.home.address.number = 1;99 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson other = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson();100 other.name = "John";101 other.home.address.number = 1;102 // neighbour103 other.neighbour = actual;104 actual.neighbour = other;105 // friends106 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson sherlock = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson();107 sherlock.name = "Sherlock";108 sherlock.home.address.number = 221;109 actual.friends.add(sherlock);110 actual.friends.add(other);111 other.friends.add(sherlock);112 other.friends.add(actual);113 objects.assertIsEqualToComparingFieldByFieldRecursively(TestData.someInfo(), actual, other, ObjectsBaseTest.noFieldComparators(), TypeComparators.defaultTypeComparators());114 }115 @Test116 public void should_fail_when_fields_differ() {117 AssertionInfo info = TestData.someInfo();118 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();119 actual.name = "John";120 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person other = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();121 other.name = "Jack";122 try {123 objects.assertIsEqualToComparingFieldByFieldRecursively(info, actual, other, ObjectsBaseTest.noFieldComparators(), TypeComparators.defaultTypeComparators());124 } catch (AssertionError err) {125 Mockito.verify(failures).failure(info, ShouldBeEqualByComparingFieldByFieldRecursively.shouldBeEqualByComparingFieldByFieldRecursive(actual, other, Arrays.asList(new Difference(Arrays.asList("name"), "John", "Jack")), CONFIGURATION_PROVIDER.representation()));126 return;127 }128 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();129 }130 @Test131 public void should_fail_when_fields_of_child_objects_differ() {132 AssertionInfo info = TestData.someInfo();133 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();134 actual.name = "John";135 actual.home.address.number = 1;136 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person other = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();137 other.name = "John";138 other.home.address.number = 2;139 try {140 objects.assertIsEqualToComparingFieldByFieldRecursively(info, actual, other, ObjectsBaseTest.noFieldComparators(), TypeComparators.defaultTypeComparators());141 } catch (AssertionError err) {142 Mockito.verify(failures).failure(info, ShouldBeEqualByComparingFieldByFieldRecursively.shouldBeEqualByComparingFieldByFieldRecursive(actual, other, Arrays.asList(new Difference(Arrays.asList("home.address.number"), 1, 2)), CONFIGURATION_PROVIDER.representation()));143 return;144 }145 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();146 }147 @Test148 public void should_have_error_message_with_differences_and_path_to_differences() {149 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();150 actual.name = "Jack";151 actual.home.address.number = 1;152 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person other = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();153 other.name = "John";154 other.home.address.number = 2;155 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(actual).isEqualToComparingFieldByFieldRecursively(other)).withMessage(String.format(("%nExpecting:%n <%s>%nto be equal to:%n <%s>%n" + (((((("when recursively comparing field by field, but found the following difference(s):%n%n" + "Path to difference: <home.address.number>%n") + "- actual : <1>%n") + "- expected: <2>%n%n") + "Path to difference: <name>%n") + "- actual : <\"Jack\">%n") + "- expected: <\"John\">")), actual, other));156 }157 @Test158 public void should_have_error_message_with_path_to_difference_when_difference_is_in_collection() {159 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson();160 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson friendOfActual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson();161 friendOfActual.home.address.number = 99;162 actual.friends = Arrays.asList(friendOfActual);163 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson other = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson();164 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson friendOfOther = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson();165 friendOfOther.home.address.number = 10;166 other.friends = Arrays.asList(friendOfOther);167 Assertions.assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(actual).isEqualToComparingFieldByFieldRecursively(other)).withMessage(String.format(("%nExpecting:%n <%s>%nto be equal to:%n <%s>%n" + ((("when recursively comparing field by field, but found the following difference(s):%n%n" + "Path to difference: <friends.home.address.number>%n") + "- actual : <99>%n") + "- expected: <10>")), actual, other));168 }169 @Test170 public void should_not_use_equal_implementation_of_objects_to_compare() {171 AssertionInfo info = TestData.someInfo();172 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.EqualPerson actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.EqualPerson();173 actual.name = "John";174 actual.home.address.number = 1;175 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.EqualPerson other = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.EqualPerson();176 other.name = "John";177 other.home.address.number = 2;178 try {179 objects.assertIsEqualToComparingFieldByFieldRecursively(info, actual, other, ObjectsBaseTest.noFieldComparators(), TypeComparators.defaultTypeComparators());180 } catch (AssertionError err) {181 Mockito.verify(failures).failure(info, ShouldBeEqualByComparingFieldByFieldRecursively.shouldBeEqualByComparingFieldByFieldRecursive(actual, other, Arrays.asList(new Difference(Arrays.asList("home.address.number"), 1, 2)), CONFIGURATION_PROVIDER.representation()));182 return;183 }184 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();185 }186 @Test187 public void should_fail_when_comparing_unsorted_with_sorted_set() {188 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithCollection<String> actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithCollection<>(new LinkedHashSet<String>());189 actual.collection.add("bar");190 actual.collection.add("foo");191 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithCollection<String> expected = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithCollection<>(new TreeSet<String>());192 expected.collection.add("bar");193 expected.collection.add("foo");194 try {195 Assertions.assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);196 } catch (AssertionError err) {197 Assertions.assertThat(err).hasMessageContaining(String.format("Path to difference: <collection>%n"));198 Assertions.assertThat(err).hasMessageContaining(String.format("- actual : <[\"bar\", \"foo\"] (LinkedHashSet@"));199 Assertions.assertThat(err).hasMessageContaining(String.format("- expected: <[\"bar\", \"foo\"] (TreeSet@"));200 return;201 }202 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();203 }204 @Test205 public void should_fail_when_comparing_sorted_with_unsorted_set() {206 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithCollection<String> actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithCollection<>(new TreeSet<String>());207 actual.collection.add("bar");208 actual.collection.add("foo");209 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithCollection<String> expected = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithCollection<>(new LinkedHashSet<String>());210 expected.collection.add("bar");211 expected.collection.add("foo");212 try {213 Assertions.assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);214 } catch (AssertionError err) {215 Assertions.assertThat(err).hasMessageContaining(String.format("Path to difference: <collection>%n"));216 Assertions.assertThat(err).hasMessageContaining(String.format("- actual : <[\"bar\", \"foo\"] (TreeSet@"));217 Assertions.assertThat(err).hasMessageContaining(String.format("- expected: <[\"bar\", \"foo\"] (LinkedHashSet@"));218 return;219 }220 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();221 }222 @Test223 public void should_fail_when_comparing_unsorted_with_sorted_map() {224 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithMap<Long, Boolean> actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithMap<>(new LinkedHashMap<>());225 actual.map.put(1L, true);226 actual.map.put(2L, false);227 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithMap<Long, Boolean> expected = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithMap<>(new TreeMap<>());228 expected.map.put(2L, false);229 expected.map.put(1L, true);230 try {231 Assertions.assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);232 } catch (AssertionError err) {233 Assertions.assertThat(err).hasMessageContaining(String.format("Path to difference: <map>%n"));234 Assertions.assertThat(err).hasMessageContaining(String.format("- actual : <{1L=true, 2L=false} (LinkedHashMap@"));235 Assertions.assertThat(err).hasMessageContaining(String.format("- expected: <{1L=true, 2L=false} (TreeMap@"));236 return;237 }238 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();239 }240 @Test241 public void should_fail_when_comparing_sorted_with_unsorted_map() {242 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithMap<Long, Boolean> actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithMap<>(new TreeMap<Long, Boolean>());243 actual.map.put(1L, true);244 actual.map.put(2L, false);245 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithMap<Long, Boolean> expected = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithMap<>(new LinkedHashMap<Long, Boolean>());246 expected.map.put(2L, false);247 expected.map.put(1L, true);248 try {249 Assertions.assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);250 } catch (AssertionError err) {251 Assertions.assertThat(err).hasMessageContaining(String.format("Path to difference: <map>%n"));252 Assertions.assertThat(err).hasMessageContaining(String.format("- actual : <{1L=true, 2L=false} (TreeMap@"));253 Assertions.assertThat(err).hasMessageContaining(String.format("- expected: <{1L=true, 2L=false} (LinkedHashMap@"));254 return;255 }256 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();257 }258 @Test259 public void should_handle_null_field_with_field_comparator() {260 // GIVEN261 Patient adam = new Patient(null);262 Patient eve = new Patient(new Timestamp(3L));263 // THEN264 Assertions.assertThat(adam).usingComparatorForFields(AlwaysEqualComparator.ALWAY_EQUALS, "dateOfBirth", "health").isEqualToComparingFieldByFieldRecursively(eve);265 }266 @Test267 public void should_handle_null_field_with_type_comparator() {268 // GIVEN269 Patient adam = new Patient(null);270 Patient eve = new Patient(new Timestamp(3L));271 // THEN272 Assertions.assertThat(adam).usingComparatorForType(AlwaysEqualComparator.ALWAY_EQUALS_TIMESTAMP, Timestamp.class).isEqualToComparingFieldByFieldRecursively(eve);273 }274 @Test275 public void should_not_bother_with_comparators_when_fields_are_the_same() {276 // GIVEN277 Timestamp dateOfBirth = new Timestamp(3L);278 Patient adam = new Patient(dateOfBirth);279 Patient eve = new Patient(dateOfBirth);280 // THEN281 Assertions.assertThat(adam).usingComparatorForFields(NeverEqualComparator.NEVER_EQUALS, "dateOfBirth").isEqualToComparingFieldByFieldRecursively(eve);282 }283 @Test284 public void should_treat_date_as_equal_to_timestamp() {285 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();286 actual.name = "Fred";287 actual.dateOfBirth = new Date(1000L);288 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person other = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();289 other.name = "Fred";290 other.dateOfBirth = new Timestamp(1000L);291 objects.assertIsEqualToComparingFieldByFieldRecursively(TestData.someInfo(), actual, other, ObjectsBaseTest.noFieldComparators(), TypeComparators.defaultTypeComparators());292 }293 @Test294 public void should_treat_timestamp_as_equal_to_date_when_registering_a_Date_symmetric_comparator() {295 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();296 actual.name = "Fred";297 actual.dateOfBirth = new Timestamp(1000L);298 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person other = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();299 other.name = "Fred";300 other.dateOfBirth = new Date(1000L);301 TypeComparators typeComparators = new TypeComparators();302 typeComparators.put(Timestamp.class, SymmetricDateComparator.SYMMETRIC_DATE_COMPARATOR);303 objects.assertIsEqualToComparingFieldByFieldRecursively(TestData.someInfo(), actual, other, ObjectsBaseTest.noFieldComparators(), typeComparators);304 objects.assertIsEqualToComparingFieldByFieldRecursively(TestData.someInfo(), other, actual, ObjectsBaseTest.noFieldComparators(), typeComparators);305 }306 @Test307 public void should_treat_timestamp_as_equal_to_date_when_registering_a_Date_symmetric_comparator_for_field() {308 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();309 actual.name = "Fred";310 actual.dateOfBirth = new Timestamp(1000L);311 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person other = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();312 other.name = "Fred";313 other.dateOfBirth = new Date(1000L);314 Map<String, Comparator<?>> fieldComparators = new HashMap<>();315 fieldComparators.put("dateOfBirth", SymmetricDateComparator.SYMMETRIC_DATE_COMPARATOR);316 objects.assertIsEqualToComparingFieldByFieldRecursively(TestData.someInfo(), actual, other, fieldComparators, TypeComparators.defaultTypeComparators());317 }318 @Test319 public void should_be_able_to_compare_objects_with_percentages() {320 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person actual = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();321 actual.name = "foo";322 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person other = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person();323 other.name = "%foo";324 try {325 objects.assertIsEqualToComparingFieldByFieldRecursively(TestData.someInfo(), actual, other, ObjectsBaseTest.noFieldComparators(), TypeComparators.defaultTypeComparators());326 } catch (AssertionError err) {327 Assertions.assertThat(err).hasMessageContaining("Path to difference: <name>").hasMessageContaining("- expected: <\"%foo\">").hasMessageContaining("- actual : <\"foo\">");328 return;329 }330 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown();331 }332 @Test333 public void should_report_missing_property() {334 // GIVEN335 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Human joe = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Human();336 joe.name = "joe";337 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant goliath = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Giant();338 goliath.name = "joe";339 goliath.height = 3.0;340 // WHEN341 Throwable error = Assertions.catchThrowable(() -> assertThat(goliath).isEqualToComparingFieldByFieldRecursively(joe));342 // THEN343 Assertions.assertThat(error).hasMessageContaining("Human does not declare all Giant fields").hasMessageContaining("[height]");344 }345 public static class WithMap<K, V> {346 public Map<K, V> map;347 public WithMap(Map<K, V> map) {348 this.map = map;349 }350 @Override351 public String toString() {352 return String.format("WithMap [map=%s]", map);353 }354 }355 public static class WithCollection<E> {356 public Collection<E> collection;357 public WithCollection(Collection<E> collection) {358 this.collection = collection;359 }360 @Override361 public String toString() {362 return String.format("WithCollection [collection=%s]", collection);363 }364 }365 public static class Person {366 public Date dateOfBirth;367 public String name;368 public Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Home home = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Home();369 public Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person neighbour;370 @Override371 public String toString() {372 return ((("Person [name=" + (name)) + ", home=") + (home)) + "]";373 }374 }375 public static class Home {376 public Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Address address = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Address();377 @Override378 public String toString() {379 return ("Home [address=" + (address)) + "]";380 }381 }382 public static class Address {383 public int number = 1;384 @Override385 public String toString() {386 return ("Address [number=" + (number)) + "]";387 }388 }389 public static class Human extends Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person {}390 public static class Giant extends Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person {391 public double height = 3.0;392 @Override393 public String toString() {394 return (((((("Giant [name=" + (name)) + ", home=") + (home)) + ", ") + "height ") + (height)) + "]";395 }396 }397 public static class EqualPerson extends Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person {398 @Override399 public boolean equals(Object o) {400 return true;401 }402 }403 public static class FriendlyPerson extends Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.Person {404 public List<Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.FriendlyPerson> friends = new ArrayList<>();405 }406}...

Full Screen

Full Screen

Source:ShouldBeEqualByComparingFieldByFieldRecursively_create_Test.java Github

copy

Full Screen

...21import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;22import org.assertj.core.description.TextDescription;23import org.assertj.core.internal.DeepDifference;24import org.assertj.core.internal.DeepDifference.Difference;25import org.assertj.core.internal.objects.Objects_assertIsEqualToComparingFieldByFieldRecursive_Test;26import org.assertj.core.presentation.Representation;27import org.assertj.core.test.Jedi;28import org.assertj.core.test.Name;29import org.assertj.core.util.AssertionsUtil;30import org.junit.jupiter.api.Test;31public class ShouldBeEqualByComparingFieldByFieldRecursively_create_Test {32 private static final Representation REPRESENTATION = CONFIGURATION_PROVIDER.representation();33 @Test34 public void should_throw_assertion_error_rather_than_null_pointer_when_one_nested_member_is_null() {35 // GIVEN36 Jedi yoda = new Jedi("Yoda", "Green");37 Jedi noname = new Jedi(null, "Green");38 // WHEN39 Throwable throwable1 = Assertions.catchThrowable(() -> assertThat(yoda).isEqualToComparingFieldByFieldRecursively(noname));40 Throwable throwable2 = Assertions.catchThrowable(() -> assertThat(noname).isEqualToComparingFieldByFieldRecursively(yoda));41 // THEN42 Assertions.assertThat(throwable1).isInstanceOf(AssertionError.class).isNotInstanceOf(NullPointerException.class);43 Assertions.assertThat(throwable2).isInstanceOf(AssertionError.class).isNotInstanceOf(NullPointerException.class);44 }45 @Test46 public void should_use_unambiguous_fields_description_when_standard_description_of_actual_and_expected_collection_fields_values_are_identical() {47 // GIVEN48 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithCollection<String> withHashSet = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithCollection<>(new LinkedHashSet<String>());49 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithCollection<String> withSortedSet = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithCollection<>(new TreeSet<String>());50 withHashSet.collection.add("bar");51 withHashSet.collection.add("foo");52 withSortedSet.collection.addAll(withHashSet.collection);53 List<Difference> differences = DeepDifference.determineDifferences(withHashSet, withSortedSet, null, null);54 // WHEN55 // @format:off56 String message = ShouldBeEqualByComparingFieldByFieldRecursively.shouldBeEqualByComparingFieldByFieldRecursive(withHashSet, withSortedSet, differences, ShouldBeEqualByComparingFieldByFieldRecursively_create_Test.REPRESENTATION).create(new TextDescription("Test"), ShouldBeEqualByComparingFieldByFieldRecursively_create_Test.REPRESENTATION);57 // @format:on58 // THEN59 Assertions.assertThat(message).isEqualTo(String.format(("[Test] %n" + (((((((("Expecting:%n" + " <WithCollection [collection=[bar, foo]]>%n") + "to be equal to:%n") + " <WithCollection [collection=[bar, foo]]>%n") + "when recursively comparing field by field, but found the following difference(s):%n") + "%n") + "Path to difference: <collection>%n") + "- actual : <[\"bar\", \"foo\"] (LinkedHashSet@%s)>%n") + "- expected: <[\"bar\", \"foo\"] (TreeSet@%s)>")), Integer.toHexString(System.identityHashCode(withHashSet.collection)), Integer.toHexString(System.identityHashCode(withSortedSet.collection))));60 }61 @Test62 public void should_use_unambiguous_fields_description_when_standard_description_of_actual_and_expected_map_fields_values_are_identical() {63 // GIVEN64 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithMap<Long, Boolean> withLinkedHashMap = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithMap<>(new LinkedHashMap<>());65 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithMap<Long, Boolean> withTreeMap = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.WithMap<>(new TreeMap<>());66 withLinkedHashMap.map.put(1L, true);67 withLinkedHashMap.map.put(2L, false);68 withTreeMap.map.putAll(withLinkedHashMap.map);69 List<Difference> differences = DeepDifference.determineDifferences(withLinkedHashMap, withTreeMap, null, null);70 // WHEN71 // @format:off72 String message = ShouldBeEqualByComparingFieldByFieldRecursively.shouldBeEqualByComparingFieldByFieldRecursive(withLinkedHashMap, withTreeMap, differences, ShouldBeEqualByComparingFieldByFieldRecursively_create_Test.REPRESENTATION).create(new TextDescription("Test"), ShouldBeEqualByComparingFieldByFieldRecursively_create_Test.REPRESENTATION);73 // @format:on74 // THEN75 Assertions.assertThat(message).isEqualTo(String.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)>")), Integer.toHexString(System.identityHashCode(withLinkedHashMap.map)), Integer.toHexString(System.identityHashCode(withTreeMap.map))));76 }77 @Test78 public void should_precise_missing_fields_when_actual_does_not_declare_all_expected_fields() {79 // GIVEN...

Full Screen

Full Screen

Objects_assertIsEqualToComparingFieldByFieldRecursive_Test

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.internal.objects;2import org.assertj.core.api.AssertionInfo;3import org.assertj.core.api.Assertions;4import org.assertj.core.internal.ObjectsBaseTest;5import org.junit.jupiter.api.Test;6public class Objects_assertIsEqualToComparingFieldByFieldRecursive_Test extends ObjectsBaseTest {7 public void should_pass_if_actual_and_expected_are_equal() {8 objects.assertIsEqualToComparingFieldByFieldRecursive(info, actual, actual);9 }10 public void should_pass_if_actual_and_expected_are_equal_recursively() {11 objects.assertIsEqualToComparingFieldByFieldRecursive(info, actual, new Person("Yoda", new Person("Luke")));12 }13 public void should_pass_if_actual_and_expected_are_equal_recursively_in_different_order() {14 objects.assertIsEqualToComparingFieldByFieldRecursive(info, actual, new Person("Luke", new Person("Yoda")));15 }16 public void should_pass_if_actual_and_expected_are_equal_recursively_with_extra_fields() {17 objects.assertIsEqualToComparingFieldByFieldRecursive(info, actual, new Person("Yoda", new Person("Luke"), "Jedi"));18 }19 public void should_pass_if_actual_and_expected_are_equal_recursively_with_missing_fields() {20 objects.assertIsEqualToComparingFieldByFieldRecursive(info, actual, new Person("Yoda"));21 }22 public void should_fail_if_actual_is_null() {23 Assertions.assertThatNullPointerException().isThrownBy(() -> objects.assertIsEqualToComparingFieldByFieldRecursive(someInfo(), null, new Person("Yoda"))).withMessage(actualIsNull());24 }25 public void should_fail_if_expected_is_null() {26 Assertions.assertThatNullPointerException().isThrownBy(() -> objects.assertIsEqualToComparingFieldByFieldRecursive(someInfo(), actual, null)).withMessage("The object to compare actual with should not be null");27 }28 public void should_fail_if_actual_and_expected_are_not_equal() {29 AssertionInfo info = someInfo();30 Person expected = new Person("Yoda");31 try {32 objects.assertIsEqualToComparingFieldByFieldRecursive(info, actual, expected);33 } catch (AssertionError e) {34 verify(failures).failure(info, shouldBeEqualByComparingFieldByFieldRecursively(actual, expected, newArrayList("name", "boss.name"), newArrayList("Luke", "

Full Screen

Full Screen

Objects_assertIsEqualToComparingFieldByFieldRecursive_Test

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.internal.objects;2import static org.assertj.core.api.Assertions.assertThat;3import static org.assertj.core.api.Assertions.assertThatExceptionOfType;4import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull;5import static org.assertj.core.test.TestData.someInfo;6import static org.assertj.core.util.FailureMessages.actualIsNull;7import org.assertj.core.api.AssertionInfo;8import org.assertj.core.internal.ObjectsBaseTest;9import org.junit.jupiter.api.Test;10class Objects_assertIsEqualToComparingFieldByFieldRecursive_Test extends ObjectsBaseTest {11 void should_pass_if_actual_is_equal_to_other() {12 objects.assertIsEqualToComparingFieldByFieldRecursive(someInfo(), actual, actual);13 }14 void should_pass_if_actual_is_equal_to_other_according_to_custom_comparison_strategy() {15 objectsWithCustomComparisonStrategy.assertIsEqualToComparingFieldByFieldRecursive(someInfo(), actual, actual);16 }17 void should_fail_if_actual_is_not_equal_to_expected() {18 AssertionInfo info = someInfo();19 Object other = new Object();20 assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> objects.assertIsEqualToComparingFieldByFieldRecursive(info, actual, other))21 .withMessageContaining("expected: <" + other + "> but was: <" + actual + ">");22 }23 void should_fail_if_actual_is_not_equal_to_expected_according_to_custom_comparison_strategy() {24 AssertionInfo info = someInfo();25 Object other = new Object();26 assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> objectsWithCustomComparisonStrategy.assertIsEqualToComparingFieldByFieldRecursive(info, actual, other))27 .withMessageContaining("expected: <" + other + "> but was: <" + actual + ">");28 }29 void should_fail_if_actual_is_null() {30 assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> objects.assertIsEqualToComparingFieldByFieldRecursive(someInfo(), null, new Object()))31 .withMessage(actualIsNull());32 }33 void should_fail_if_other_is_null() {34 assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> objects.assertIsEqualToComparingFieldByFieldRecursive(someInfo(), actual, null))35 .withMessage(shouldNotBeNull().create());36 }

Full Screen

Full Screen

Objects_assertIsEqualToComparingFieldByFieldRecursive_Test

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.internal.objects.Objects_assertIsEqualToComparingFieldByFieldRecursive_Test;2public class test1 {3 public static void main(String[] args) {4 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test obj = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test();5 obj.should_pass_if_actual_is_equal_to_expected();6 }7}8import org.assertj.core.internal.objects.Objects_assertIsNotEqualToComparingFieldByFieldRecursive_Test;9public class test2 {10 public static void main(String[] args) {11 Objects_assertIsNotEqualToComparingFieldByFieldRecursive_Test obj = new Objects_assertIsNotEqualToComparingFieldByFieldRecursive_Test();12 obj.should_pass_if_actual_is_not_equal_to_expected();13 }14}

Full Screen

Full Screen

Objects_assertIsEqualToComparingFieldByFieldRecursive_Test

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.api.objects;2import org.assertj.core.api.Objects_assertIsEqualToComparingFieldByFieldRecursive_Test;3public class Objects_assertIsEqualToComparingFieldByFieldRecursive_Test extends Objects_assertIsEqualToComparingFieldByFieldRecursive_Test {4}5package org.assertj.core.api.objects;6import org.assertj.core.api.Objects_assertIsEqualToComparingFieldByField_Test;7public class Objects_assertIsEqualToComparingFieldByField_Test extends Objects_assertIsEqualToComparingFieldByField_Test {8}9package org.assertj.core.api.objects;10import org.assertj.core.api.Objects_assertIsNotEqualToComparingFieldByFieldRecursive_Test;11public class Objects_assertIsNotEqualToComparingFieldByFieldRecursive_Test extends Objects_assertIsNotEqualToComparingFieldByFieldRecursive_Test {12}13package org.assertj.core.api.objects;14import org.assertj.core.api.Objects_assertIsNotEqualToComparingFieldByField_Test;15public class Objects_assertIsNotEqualToComparingFieldByField_Test extends Objects_assertIsNotEqualToComparingFieldByField_Test {16}17package org.assertj.core.api.objects;18import org.assertj.core.api.Objects_assertIsNotSameAs_Test;19public class Objects_assertIsNotSameAs_Test extends Objects_assertIsNotSameAs_Test {20}21package org.assertj.core.api.objects;22import org.assertj.core.api.Objects_assertIsSameAs_Test;23public class Objects_assertIsSameAs_Test extends Objects_assertIsSameAs_Test {24}25package org.assertj.core.api.objects;26import org.assertj.core.api.Objects_assertIsNull_Test;27public class Objects_assertIsNull_Test extends Objects_assertIsNull_Test {28}

Full Screen

Full Screen

Objects_assertIsEqualToComparingFieldByFieldRecursive_Test

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.Assertions;2import org.assertj.core.internal.objects.Objects_assertIsEqualToComparingFieldByFieldRecursive_Test;3import org.assertj.core.internal.objects.ObjectsBaseTest;4import org.junit.Test;5public class Objects_assertIsEqualToComparingFieldByFieldRecursive_TestTest extends ObjectsBaseTest {6 public void test() {7 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test objects_assertIsEqualToComparingFieldByFieldRecursive_Test = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test();8 Assertions.assertThat(objects_assertIsEqualToComparingFieldByFieldRecursive_Test).isNotNull();9 }10}

Full Screen

Full Screen

Objects_assertIsEqualToComparingFieldByFieldRecursive_Test

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.internal.objects;2import org.junit.Test;3import static org.assertj.core.api.Assertions.assertThat;4import static org.assertj.core.api.Assertions.catchThrowable;5import static org.assertj.core.error.ShouldBeEqual.shouldBeEqual;6import static org.assertj.core.test.TestData.someInfo;7import static org.assertj.core.util.FailureMessages.actualIsNull;8import static org.assertj.core.util.Objects.areEqual;9import static org.assertj.core.util.Objects.areNotEqual;10import static org.assertj.core.util.Objects.hashCodeFor;11import static org.assertj.core.util.Objects.instanceOf;12import static org.assertj.core.util.Objects.isNullOrEmpty;13import static org.assertj.core.util.Objects.nonNull;14import static org.assertj.core.util.Objects.nullSafeEquals;15import static org.assertj.core.util.Objects.nullSafeHashCode;16import static org.assertj.core.util.Objects.nullSafeToString;17import static org.assertj.core.util.Objects.requireNonNull;18import static org.assertj.core.util.Objects.setFrom;19import static org.assertj.core.util.Objects.setFromIterable;20import static org.assertj.core.util.Objects.toIterable;21import static org.assertj.core.util.Objects.toSet;22import static org.assertj.core.util.Objects.tuple;23import static org.assertj.core.util.Objects.tupleOf;24import static org.assertj.core.util.Objects.tupleOfArray;25import static org.assertj.core.util.Objects.tupleOfIterables;26import static org.assertj.core.util.Objects.tupleOfLists;27import static org.assertj.core.util.Objects.tupleOfSets;28import static org.assertj.core.util.Objects.tupleOfVarargs;29import static org.assertj.core.util.Objects.tuples;30import static org.assertj.core.util.Objects.tuplesOf;31import static org.assertj.core.util.Objects.tuplesOfArray;32import static org.assertj.core.util.Objects.tuplesOfIterables;33import static org.assertj.core.util.Objects.tuplesOfLists;34import static org.assertj.core.util.Objects.tuplesOfSets;35import static org.assertj.core.util.Objects.tuplesOfVarargs;36import static org.assertj.core.util.Objects.unmodifiableSet;37import static org.assertj.core.util.Objects.unmodifiableSortedSet;38import static org.assertj.core.util.Objects.unmodifiableTreeSet;39import static org.assertj.core.util.Objects.unmodifiableHashSet;40import static org.assertj.core.util.Objects.unmodifiableLinkedHashSet;41import static org.assertj.core.util.Objects.unmodifiableList;42import static org.assertj.core.util.Objects.unmodifiableArrayList;43import static org.assertj.core.util.Objects.unmodifiableLinkedList;44import static org.assertj.core.util.Objects.unmodifiableMap;45import static org.assertj.core.util.Objects.unmodifiableSortedMap;46import static org.assertj.core.util.Objects.unmodifiableTree

Full Screen

Full Screen

Objects_assertIsEqualToComparingFieldByFieldRecursive_Test

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import org.assertj.core.api.Assertions;3import org.assertj.core.internal.objects.Objects_assertIsEqualToComparingFieldByFieldRecursive_Test;4public class assertIsEqualToComparingFieldByFieldRecursive_Test {5 public void test1() {6 Objects_assertIsEqualToComparingFieldByFieldRecursive_Test obj = new Objects_assertIsEqualToComparingFieldByFieldRecursive_Test();7 obj.assertIsEqualToComparingFieldByFieldRecursive_should_compare_recursive_fields();8 }9}10 at org.junit.Assert.assertEquals(Assert.java:115)11 at org.assertj.core.internal.objects.Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.assertIsEqualToComparingFieldByFieldRecursive_should_compare_recursive_fields(Objects_assertIsEqualToComparingFieldByFieldRecursive_Test.java:42)

Full Screen

Full Screen

Objects_assertIsEqualToComparingFieldByFieldRecursive_Test

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.Assertions;2import org.assertj.core.internal.Objects;3import org.junit.jupiter.api.Test;4public class Objects_assertIsEqualToComparingFieldByFieldRecursive_Test {5 public void test() {6 Objects objects = new Objects();7 objects.assertIsEqualToComparingFieldByFieldRecursive(new Object(), new Object());8 }9}10import org.assertj.core.api.Assertions;11import org.assertj.core.internal.Objects;12import org.junit.jupiter.api.Test;13public class Objects_assertIsEqualToComparingFieldByFieldRecursive_Test {14 public void test() {15 Objects objects = new Objects();16 objects.assertIsEqualToComparingFieldByFieldRecursive(new Object(), new Object(), Assertions.within(1));17 }18}19import org.assertj.core.api.Assertions;20import org.assertj.core.internal.Objects;21import org.junit.jupiter.api.Test;22public class Objects_assertIsEqualToComparingFieldByFieldRecursive_Test {23 public void test() {24 Objects objects = new Objects();25 objects.assertIsEqualToComparingFieldByFieldRecursive(new Object(), new Object(), Assertions.within(1), Assertions.within(1));26 }27}28import org.assertj.core.api.Assertions;29import org.assertj.core.internal.Objects;30import org.junit.jupiter.api.Test;31public class Objects_assertIsEqualToComparingFieldByFieldRecursive_Test {32 public void test() {33 Objects objects = new Objects();34 objects.assertIsEqualToComparingFieldByFieldRecursive(new Object(), new Object(), Assertions.within(1), Assertions.within(1), Assertions.within(1));35 }36}37import org

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Assertj automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Objects_assertIsEqualToComparingFieldByFieldRecursive_Test

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful