How to use RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test class of org.assertj.core.api.recursive.comparison package

Best Assertj code snippet using org.assertj.core.api.recursive.comparison.RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test

Source:RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test.java Github

copy

Full Screen

...22import org.assertj.core.internal.objects.data.Person;23import org.assertj.core.internal.objects.data.PersonDto;24import org.assertj.core.internal.objects.data.PersonDtoWithPersonNeighbour;25import org.junit.jupiter.api.Test;26public class RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test extends RecursiveComparisonAssert_isEqualTo_BaseTest {27 @Test28 public void should_pass_by_default_when_objects_data_are_equals_whatever_their_types_are() {29 // GIVEN30 Person actual = new Person("John");31 actual.home.address.number = 1;32 actual.dateOfBirth = new Date(123);33 actual.neighbour = new Person("Jack");34 actual.neighbour.home.address.number = 123;35 actual.neighbour.neighbour = new Person("James");36 actual.neighbour.neighbour.home.address.number = 124;37 PersonDto expected = new PersonDto("John");38 expected.home.address.number = 1;39 expected.dateOfBirth = new Date(123);40 expected.neighbour = new PersonDto("Jack");41 expected.neighbour.home.address.number = 123;42 expected.neighbour.neighbour = new PersonDto("James");43 expected.neighbour.neighbour.home.address.number = 124;44 // THEN45 Assertions.assertThat(actual).usingRecursiveComparison().isEqualTo(expected);46 }47 @Test48 public void should_pass_in_strict_type_check_mode_when_objects_data_are_equals_and_expected_type_is_compatible_with_actual_type() {49 // GIVEN50 Person actual = new Person("John");51 actual.home.address.number = 1;52 actual.dateOfBirth = new Date(123);53 actual.neighbour = new Person("Jack");54 actual.neighbour.home.address.number = 123;55 actual.neighbour.neighbour = new Person("James");56 actual.neighbour.neighbour.home.address.number = 124;57 Giant expected = new Giant();58 expected.name = "John";59 expected.home.address.number = 1;60 expected.dateOfBirth = new Date(123);61 expected.neighbour = new Giant();62 expected.neighbour.name = "Jack";63 expected.neighbour.home.address.number = 123;64 expected.neighbour.neighbour = new Person("James");65 expected.neighbour.neighbour.home.address.number = 124;66 Person expected2 = new Person("John");67 expected2.home.address.number = 1;68 expected2.dateOfBirth = new Date(123);69 expected2.neighbour = new Person("Jack");70 expected2.neighbour.home.address.number = 123;71 expected2.neighbour.neighbour = new Person("James");72 expected2.neighbour.neighbour.home.address.number = 124;73 // WHEN74 recursiveComparisonConfiguration.strictTypeChecking(true);75 // THEN76 Assertions.assertThat(actual).usingRecursiveComparison().withStrictTypeChecking().isEqualTo(expected).isEqualTo(expected2);77 }78 @Test79 public void should_fail_in_strict_type_checking_mode_when_actual_and_expected_have_the_same_data_but_incompatible_types() {80 // GIVEN81 Person actual = new Person("John");82 actual.home.address.number = 1;83 actual.dateOfBirth = new Date(123);84 actual.neighbour = new Person("Jack");85 actual.neighbour.home.address.number = 123;86 PersonDtoWithPersonNeighbour expected = new PersonDtoWithPersonNeighbour("John");87 expected.home.address.number = 1;88 expected.dateOfBirth = new Date(123);89 expected.neighbour = new Person("Jack");90 expected.neighbour.home.address.number = 123;91 recursiveComparisonConfiguration.strictTypeChecking(true);92 // WHEN93 compareRecursivelyFailsAsExpected(actual, expected);94 // THEN95 ComparisonDifference difference = RecursiveComparisonAssert_isEqualTo_BaseTest.diff("", actual, expected, "actual and expected are considered different since the comparison enforces strict type check and expected type org.assertj.core.internal.objects.data.PersonDtoWithPersonNeighbour is not a subtype of actual type org.assertj.core.internal.objects.data.Person");96 verifyShouldBeEqualByComparingFieldByFieldRecursivelyCall(actual, expected, difference);97 }98 @Test99 public void should_fail_in_strict_type_checking_mode_when_actual_and_expected_fields_have_the_same_data_but_incompatible_types() {100 // GIVEN101 RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test.Something withA = new RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test.Something(new RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test.A(10));102 RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test.Something withB = new RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test.Something(new RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test.B(10));103 recursiveComparisonConfiguration.strictTypeChecking(true);104 // WHEN105 compareRecursivelyFailsAsExpected(withA, withB);106 // THEN107 // inner comparison fails as the fields have different types108 ComparisonDifference valueDifference = RecursiveComparisonAssert_isEqualTo_BaseTest.diff("inner", withA.inner, withB.inner, "the fields are considered different since the comparison enforces strict type check and org.assertj.core.api.recursive.comparison.RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test$B is not a subtype of org.assertj.core.api.recursive.comparison.RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test$A");109 verifyShouldBeEqualByComparingFieldByFieldRecursivelyCall(withA, withB, valueDifference);110 }111 private static class Something {112 RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test.Inner inner;// can be A or B113 public Something(RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test.Inner inner) {114 this.inner = inner;115 }116 }117 private static class Inner {118 @SuppressWarnings("unused")119 int value;120 }121 private static class A extends RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test.Inner {122 public A(int value) {123 this.value = value;124 }125 }126 private static class B extends RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test.Inner {127 public B(int value) {128 this.value = value;129 }130 }131}...

Full Screen

Full Screen

RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test

Using AI Code Generation

copy

Full Screen

1package org.assertj.core.api.recursive.comparison;2import static org.assertj.core.api.Assertions.assertThat;3import static org.assertj.core.api.Assertions.assertThatExceptionOfType;4import static org.assertj.core.api.Assertions.catchThrowable;5import static org.assertj.core.api.BDDAssertions.then;6import static org.assertj.core.api.recursive.comparison.RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test.TestData.someInfo;7import static org.mockito.Mockito.mock;8import org.assertj.core.api.RecursiveComparisonAssert_isEqualTo_strictTypeCheck_TestBase;9import org.assertj.core.internal.objects.data.Person;10import org.assertj.core.util.introspection.IntrospectionError;11import org.junit.jupiter.api.Test;12class RecursiveComparisonAssert_isEqualTo_strictTypeCheck_Test extends RecursiveComparisonAssert_isEqualTo_strictTypeCheck_TestBase {13 void should_fail_when_actual_and_expected_have_different_types() {14 Person actual = new Person();15 Object expected = mock(Person.class);16 Throwable thrown = catchThrowable(() -> assertThat(actual).usingRecursiveComparison()17 .isEqualTo(expected));18 then(thrown).isInstanceOf(AssertionError.class)19 .hasMessageContaining("Expecting actual value to be of type")20 .hasMessageContaining("but was of type");21 }22 void should_fail_with_nice_error_message_when_actual_and_expected_have_different_types_and_configured_to_use_strict_type_check() {23 Person actual = new Person();24 Object expected = mock(Person.class);25 Throwable thrown = catchThrowable(() -> assertThat(actual).usingRecursiveComparison()26 .withStrictTypeChecking()27 .isEqualTo(expected));28 then(thrown).isInstanceOf(AssertionError.class)29 .hasMessageContaining("Expecting actual value to be of type")30 .hasMessageContaining("but was of type");31 }32 void should_fail_with_introspection_error_when_actual_and_expected_have_different_types_and_configured_to_use_strict_type_check_and_ignore_all_actual_null_fields() {33 Person actual = new Person();34 Object expected = mock(Person.class);35 Throwable thrown = catchThrowable(() -> assertThat(actual).usingRecursiveComparison()36 .withStrictTypeChecking()37 .ignoringAllActualNullFields()38 .isEqualTo(expected));39 then(thrown).isInstanceOf(Introspection

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 RecursiveComparisonAssert_isEqualTo_strictTypeCheck_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