-
-
Notifications
You must be signed in to change notification settings - Fork 683
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
Support multiple AfterAssertionErrorCollected callbacks #3313
Conversation
@Achitheus that's interesting, could you give us a real life use case to show why this could be useful ? |
@joel-costigliola Im gonna add AssertJ soft assertions support for java Allure reports. I am already done with it and even tested, but haven't suggested PR at the moment. My solution relys on this functionality to detect assertion error and mark current step as failed and then escalate this status to all outer steps of the step chain. |
I should have pushed several commits at once. Sorry. I hope you don't have github actions proccesing time restrictions or something :) |
@joel-costigliola what do you think? Could you please run actions one more time? |
Sorry I missed your reply, I'll think about it this week end, but gut feeling is it should be ok |
@joel-costigliola I'm not rushing you but just reminding :) |
Thanks for the reminder, I'll put it for the next version 3.26.0 |
assertj-core/src/main/java/org/assertj/core/api/DefaultAssertionErrorCollector.java
Outdated
Show resolved
Hide resolved
assertj-core/src/main/java/org/assertj/core/api/DefaultAssertionErrorCollector.java
Show resolved
Hide resolved
...rg/assertj/core/api/DefaultAssertionErrorCollector_setAfterAssertionErrorCollected_Test.java
Outdated
Show resolved
Hide resolved
...rg/assertj/core/api/DefaultAssertionErrorCollector_setAfterAssertionErrorCollected_Test.java
Outdated
Show resolved
Hide resolved
...rg/assertj/core/api/DefaultAssertionErrorCollector_setAfterAssertionErrorCollected_Test.java
Outdated
Show resolved
Hide resolved
@Achitheus thanks, PR commented. |
652d290
to
a5f9611
Compare
@joel-costigliola Thank you for your insightful comments! Let me know if there is anything else I can do/fix. |
a5f9611
to
076bc70
Compare
@joel-costigliola I think I finally realized my mistake. I should use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second round of comments, thanks @Achitheus
assertj-core/src/main/java/org/assertj/core/api/DefaultAssertionErrorCollector.java
Outdated
Show resolved
Hide resolved
softly.collectAssertionError(new AssertionError("hello")); | ||
// THEN | ||
then(throwables).hasSize(10); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a unit test to check that setAfterAssertionErrorCollected replace all registered callback with the one specified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. But I would like to clarify whether this test should be moved from current class
DefaultAssertionErrorCollector_addAfterAssertionErrorCollected_Test
to this new one
DefaultAssertionErrorCollector_setAfterAssertionErrorCollected_Test
?
Or even moved to org/example/test/DefaultAssertionErrorCollector_Test.java
Or let it be in the current class, but rename the class to
DefaultAssertionErrorCollector_afterAssertionErrorCollected_methods_Test
or
DefaultAssertionErrorCollector_callbacks_Test
or something?
076bc70
to
5a57766
Compare
@joel-costigliola build success locally. |
Integrated thanks @Achitheus ! |
Check List:
Let AssertJ integrations safely rely on this fuctionality!
Without this multiple callbacks support there is a problem with using
DefaultAssertionErrorCollector.setAfterAssertionErrorCollected()
method.It can be used only by user at the moment, but not by another frameworks developers .
Why do I think so? Because
callback
field in theDefaultAssertionErrorCollector
class is not instance of anyCollection<AfterAssertionErrorCollected>
type, but is justAfterAssertionErrorCollected
. ThussetAfterAssertionErrorCollected()
method can be executed only once for eachSoftAssertions
object (by exact single actor - user), because every next call leads to overriding and erasing previously set callback.