Add option to ignore compared fields existence check#3836
Add option to ignore compared fields existence check#3836kssumin wants to merge 1 commit intoassertj:mainfrom
Conversation
|
Thanks @kssumin, I will review your PR shortly ! |
There was a problem hiding this comment.
I'm not completely sure what we are testing here, we check that the config has the expected ignoreNonExistentFields value but I don't get the point of checking int compare = configurableRecursiveFieldByFieldComparator.compare(actual, other);.
Instead of these two tests, could we add a test in RecursiveComparisonAssert_isEqualTo_comparingOnlyFields_Test and reproduce the test example in the initial issue #3806 (comment) ? if the implementation is correct, the test should pass
There was a problem hiding this comment.
We could in addition also add a test with the code example from the javadoc (with BaseClass, Subclass1 and 2)
Thanks !
There was a problem hiding this comment.
Can you rename to ignoringNonExistentComparedFields which is more accurate since it only impacts the compared fields declared by the user.
|
Thanks @kssumin, first round of code review done. |
28a29e6 to
204e149
Compare
|
@joel-costigliola Thank you for your review and suggestions! I've made the following changes based on your feedback:
I've maintained the test structure with GIVEN/WHEN/THEN pattern and made sure all tests verify both success and failure cases. Let me know if you'd like me to make any additional changes! |
This adds a new feature to recursive comparison that allows ignoring fields that don't exist in the actual object. This is particularly useful when comparing polymorphic objects where certain fields might only exist in some subtypes. Fixes assertj#3806 Signed-off-by: Kim Sumin <ksoomin25@gmail.com>
204e149 to
0e7a6d5
Compare
|
Integrated thanks @kssumin ! |
This adds a new option (ignoringNonExistentFields) to recursive comparison that allows polymorphic objects with different field structures to be compared effectively. When enabled, the comparison will skip field existence validation, which is useful when comparing objects of different subtypes where some fields might only exist in certain implementations.
Overview
This PR adds a new feature to the recursive comparison functionality that allows ignoring non-existent field checks. This is particularly useful when comparing polymorphic objects where some fields might not exist in all subtypes.
Implementation Details
ignoreNonExistentFieldsboolean flag toRecursiveComparisonConfigurationignoringNonExistentFields()method toRecursiveComparisonAssertcheckComparedFieldsExistwhen this option is enabledExample Use Case
When comparing objects like:
Regular recursive comparison would fail due to field existence checks. With this new option:
Check List: