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
That is nice, I appreciate a lot, but my problem is, and this is often overlooked: we should report multiple failures at once (where assertions are independent of each other). To give a better example we can:
Use JUnit's assertAll
Use AssertJ's assertSoftly
Or use AssertJ's tuple and/or extracting (if lists are involved)
Mockito has no way to catch multiple failures thrown by the Consumer of assertArg. If such behavior is desired, the writer of the Consumer should take care of it, e.g.:
verify(otherServiceMock).doStuff(assertArg(param ->
assertThat(param).satisfies(
p -> assertThat(p.getField1()).isEqualTo("value1"),
p -> assertThat(p.getField2()).isEqualTo("value2")
)));
(manually written, beware of typos)
To support this use case, Mockito could add a new assertArg(Consumer...) which behaves like AssertJ satisfies and would allow to write something like:
I've seen that Mockito adds assertArg in version 5.3.0 (#2285):
That is nice, I appreciate a lot, but my problem is, and this is often overlooked: we should report multiple failures at once (where assertions are independent of each other). To give a better example we can:
assertAll
assertSoftly
tuple
and/orextracting
(if lists are involved)Example:
Or whatever code style you find more readable.
Sadly, several frameworks/libraries get it wrong as well:
andExpectAll
in Spring Framework v5.3.10The text was updated successfully, but these errors were encountered: