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
Add usingRecursiveComparison for Iterables #1238
Comments
Hello @joel-costigliola |
The thing is that assertion is not recursive which I think is what users would expect from it so I don't want to add this improvement to Fortunately the new recursive API #1002 has been mostly implemented but not yet the direct support for iterables which is what is requested here. If it did you would be able to write: List frodos = asList(new TolkienCharacter("Frodo1", 33, HOBBIT), new TolkienCharacter("Frodo2", 34, MAN));
List sams= asList(new TolkienCharacter("Sam1", 38, HOBBIT), new TolkienCharacter("Sam2", 39, MAN);
// frodo and sam are equals when ignoring name and age as the only remaining field is race
assertThat(frodos).usingRecursiveComparison().
.ignoringFields("name", "age")
.isEqualTo(sams); @haruntuncay if you feel like it you are welcome to give it a try. |
Hello @joel-costigliola, Hope you are doing well. I am going to give this issue a try this week and I wanted to ask your opinion for some pointers on the implementation first. I was thinking of creating a new class, namely Is my understanding of the requested API correct ? And could you please share your opinions and ideas on the design ? Thank you in advance. |
@haruntuncay I think we should try a simpler approach by adding Let me know if you need further clarifications. |
@joel-costigliola, Thank you for the help and please excuse my inadequate design decisions😄 as I am a student and not a seasoned developer. But I really would like to help the project with this issue as it can help me improve a lot. Therefore, could you please clarify how we can achieve a chain structure like this
since Thank you in advance and please excuse me if I am causing a bit of a pain in the head 😄. |
Try first to add I'm not sure what you mean by associating |
Sure. For example in here, (without
the I thought, by adding
the goal was to use the new Could you please explain where I am mistaken ? |
Alright, I get it now, I was thinking of simply adding the existing I think an implementation worth exploring is to define (as you suggested) a When an assertion is called (eg.
The comparator is like the existing I would suggest to write a PoC of |
Hello @joel-costigliola, Hope you are well. As you suggested, I have implemented a PoC and it seems to work well. I have created a new branch in my fork of AssertJ and committed here. Could you please check it out when you have the time ? I would love to hear your feedback on it. Thanks in advance and hoping to hear from you soon. (btw had to edit the fork because I pushed some unnecessary files as well.) |
@haruntuncay could you create a PR even if it is not ready ? it is easier to give feedback on a PR |
@joel-costigliola, just wanted to notify that I have created the PR. Thanks in advance for the review. |
I'm a bit busy on working for releasing 3.13.0, I'll have a look at your PR likely next week. Ping me if you don't hear from me within 2 weeks ;-) |
I added To expose more assertions we need to take the road of We'll give it shot in 3.16.0 |
Addressed and documented with https://assertj.github.io/doc/#assertj-core-recursive-comparison-for-iterable |
Summary
Currently there is a feature to exclude fields using isEqualToIgnoringGivenFields while asserting a bean
http://joel-costigliola.github.io/assertj/assertj-core-features-highlight.html
We are exactly looking for similar feature while asserting list (or Iterable Objects)
Example
List frodos = Arrays.asList(
new TolkienCharacter("Frodo1", 33, HOBBIT),
new TolkienCharacter("Frodo2", 34, MAN));
List sams= Arrays.asList(
new TolkienCharacter("Sam1", 38, HOBBIT);
new TolkienCharacter("Sam2", 39, MAN);
// frodo and sam are equals when ignoring name and age as the only remaining field is race
assertThat(frodos).isEqualToIgnoringGivenFields(sams, "name", "age"); // OK both are HOBBIT
// ... but they are not equals if only age is ignored as their names differ.
assertThat(frodos).isEqualToIgnoringGivenFields(sams, "age"); // FAIL
The text was updated successfully, but these errors were encountered: