Verification matcher for inline asserting

Skip to first unread message

Marcin Zajączkowski

Jan 26, 2022, 5:26:31 AMJan 26
to mockito
Hi. I've been treating my mockito-java8 as a deprecated project - with all the major features already available in mockito-core. However, recently, I've been migrating some big project from Mockito 1.x to 2.x/4.x and I wasn't able to find a simple way to perform inline asserting in verification, such as:

    void shouldAllowToUseAssertionInLambdaWithPrimitiveAsArgument() {
        verify(ts).fireTorpedo(assertArg(i -> assertThat(i).isEqualTo(2)));

As ArgumentMacher has a return type, it is problematic to do it in one line (an extra "return true" is required - a custom Matcher has to be created).

Of course it can also be done with ArgumentCaptor, but it is even 3 lines instead od 1.

The implementation in mockito-java8 is trivial:

If I missed something existing, please let me know. In the other case, I wonder, if you are open to accept assertArg() addition to the mockito-core (to be able to officially deprecated mockito-java8 :) )?


-- - Solid Soft - Working code is not enough

Tim van der Lippe

Jan 26, 2022, 5:27:29 PMJan 26
to mockito
Hey Marcin,

Yes, that makes sense to me. I think the best place to add this method would be `AdditionalMatchers`. Looking forward to the PR!


Op wo 26 jan. 2022 om 10:26 schreef Marcin Zajączkowski <>:
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages