You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
equals and hashCode are used in the implementation of satisfiesExactlyInAnyOrder (when they definitely aren't needed). This can result in incorrect assertion results.
Expecting actual:
[StringAndInt{string='X', integer=1}, StringAndInt{string='X', integer=2}]
to satisfy all the consumers in any order.
but should pass.
The problem is that the use of List::remove in the implementation results in the wrong element being removed.
In general we believe there are a number of bugs in assertj due to unnecessary usages of equals and hashCode, and think that the best way to weed them out is to have unit tests using classes where equals and hashCode throw exceptions.
The text was updated successfully, but these errors were encountered:
PBoddington
changed the title
Bug in satisfiesExactlyInAnyOrder due to usages of equals and hashCode in the implementation
Bug in satisfiesExactlyInAnyOrder due to usages of equals and hashCode in the implementation
Jan 19, 2024
scordio
changed the title
Bug in satisfiesExactlyInAnyOrder due to usages of equals and hashCode in the implementationsatisfiesExactlyInAnyOrder fails if actual overrides equalsJan 21, 2024
In general we believe there are a number of bugs in assertj due to unnecessary usages of equals and hashCode, and think that the best way to weed them out is to have unit tests using classes where equals and hashCode throw exceptions.
In general we believe there are a number of bugs in assertj due to unnecessary usages of equals and hashCode, and think that the best way to weed them out is to have unit tests using classes where equals and hashCode throw exceptions.
Do you have any specific examples in mind?
One other thing was #3340 but it's hard to give other specific examples right now. This came about because as an experiment to see if people in our org were writing code relying on undocumented equals/hashCode behaviour of certain core classes, we changed the implementations to simply throw exceptions to see what tests failed. Many of the exceptions we saw were coming from assertj itself. The reason it's so difficult to say whether these are bugs or not is that it would not be a bug in itself for assertj to be calling equals/hashCode on the arguments passed. I'd have to go through the exceptions and find if equals/hashCode was being used correctly. In this particular case I was able to see quite quickly that it was a bug, but other exceptions require more analysis. I'll create more issues if I do find any more.
equals
andhashCode
are used in the implementation ofsatisfiesExactlyInAnyOrder
(when they definitely aren't needed). This can result in incorrect assertion results.Example of the issue:
This test fails with
but should pass.
The problem is that the use of
List::remove
in the implementation results in the wrong element being removed.In general we believe there are a number of bugs in assertj due to unnecessary usages of
equals
andhashCode
, and think that the best way to weed them out is to have unit tests using classes whereequals
andhashCode
throw exceptions.The text was updated successfully, but these errors were encountered: