Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignoringFieldsOnlyLhsHas for usingRecursiveComparison #3429

Open
WorkProg opened this issue Apr 15, 2024 · 1 comment
Open

ignoringFieldsOnlyLhsHas for usingRecursiveComparison #3429

WorkProg opened this issue Apr 15, 2024 · 1 comment
Labels
theme: recursive comparison An issue related to the recursive comparison

Comments

@WorkProg
Copy link

WorkProg commented Apr 15, 2024

Feature summary

A function that automatically ignores any fields that only the lhs has when comparing with recursiveComparision. Related to #2143, but for actual POJOs. This would basically mean, add an ignoringFields("every", "field", "lhs has", "but", "rhs has not").

Example

record A(String hello, int world){}
record B(String hello, int planet){}
record C( String hello) {}

var a = A("hello", 1);
assertThat(a).usingRecursiveComparison().ignoringFieldsOnlyLhsHas().isEqualTo(B("hello", 1)); // complain about a not having `planet`

assertThat(a).usingRecursiveComparison().ignoringFieldsOnlyLhsHas().isEqualTo(C("hello")); // this is correct (`world` is ignored)

assertThat(a).usingRecursiveComparison().ignoringFieldsOnlyLhsHas().isEqualTo(C("not hello")); // this fails because `"hello" != "not hello"`
@WorkProg
Copy link
Author

I'd also be fine with a function that is just ignoringUnknownFields and doesn't make a difference between the lhs and rhs.

@scordio scordio added the theme: recursive comparison An issue related to the recursive comparison label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: recursive comparison An issue related to the recursive comparison
Projects
None yet
Development

No branches or pull requests

2 participants