I am using AssertJ for assertion and below is current implementation. Below is HospitalDailyCashProductDetails and HospitalDailyCashCoversDetailsUI details, here in both the keys are same.
HospitalDailyCashProductDetails(productId=4148, productCode=4148, premiumAmount=600, productDescription=(Hospital Daily Cash Cover), productName=Group Safeguard Insurance, sumInsured=₹ 750.00 per day for up to 30 days, validityPeriod=12 Months, dateOfIssuance=04/03/2024)
HospitalDailyCashCoversDetailsUI(premiumAmount=₹600.00, sumInsured=₹ 750.00 per day for up to 30 days, validityPeriod=12 Months, dateOfIssuance=04/03/2024)
current implementation.
HospitalDailyCashProductDetails hospitalDailyCashProductDetails = testContext.getContext(ScenarioContextKey.HOSPITAL_DAILY_CASH_COVERS);
HospitalDailyCashCoversDetailsUI hospitalDailyCashCoversDetailsUI = hospitalDailyCashCovers.getHospitalDailyCashCoversDetailsUI();
String strExpectedPremiumAmount = hospitalDailyCashProductDetails.getPremiumAmount();
String strActualPremiumAmount = hospitalDailyCashCoversDetailsUI.getPremiumAmount();
testContext.softAssertion().assertThat(strActualPremiumAmount).withFailMessage("Expected Premium Amount is %s, but was %s", strExpectedPremiumAmount, strActualPremiumAmount).contains(strExpectedPremiumAmount);
String strExpectedSumInsured = hospitalDailyCashProductDetails.getSumInsured().replaceAll("₹","₹");
String strActualSumInsured = hospitalDailyCashCoversDetailsUI.getSumInsured();
testContext.softAssertion().assertThat(strActualSumInsured).withFailMessage("Expected Sum Assured is %s, but was %s", strExpectedSumInsured, strActualSumInsured).isEqualTo(strExpectedSumInsured);
String strExpectedValidityPeriod = hospitalDailyCashProductDetails.getValidityPeriod();
String strActualValidityPeriod = hospitalDailyCashCoversDetailsUI.getValidityPeriod();
testContext.softAssertion().assertThat(strActualValidityPeriod).withFailMessage("Expected Validity Period is %s, but was %s", strExpectedValidityPeriod, strActualValidityPeriod).isEqualTo(strExpectedValidityPeriod);
String strExpectedDateOfIssuance = hospitalDailyCashProductDetails.getDateOfIssuance();
String strActualDateOfIssuance = hospitalDailyCashCoversDetailsUI.getDateOfIssuance();
testContext.softAssertion().assertThat(strActualDateOfIssuance).withFailMessage("Expected Date Of Insurance is %s, but was %s", strExpectedDateOfIssuance, strActualDateOfIssuance).isEqualTo(strExpectedDateOfIssuance);
in the above code testContext.softAssertion() is my custom Soft Assertion
The recursive comparison is documented here: https://assertj.github.io/doc/#assertj-core-recursive-comparison
The RecursiveComparisonAssert fluent API exposes methods to configure the comparison behavior (after calling usingRecursiveComparison()).
An alternative way you can specify the configuration by calling usingRecursiveComparison(config) and providing a config, this allow to set the config once and reuse in different tests instead building a new one each time (it really depends if that's a use case for you or not)