Skip to content
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 @Captor injection in JUnit 5 method parameters #1382

Closed
filiphr opened this issue May 7, 2018 · 5 comments · Fixed by #3133
Closed

Support @Captor injection in JUnit 5 method parameters #1382

filiphr opened this issue May 7, 2018 · 5 comments · Fixed by #3133

Comments

@filiphr
Copy link

filiphr commented May 7, 2018

There is already an open PR #1350 that proposes and adds support for @Mock. This issue is to extend on that PR if / when it gets merged to also support the @Captor annotation in method parameters. This would allow to inject method specific generic ArgumentCaptor that can't be caught with ArgumentCaptor.of(Class).

@schrieveslaach
Copy link

schrieveslaach commented Aug 6, 2020

Is there any update on this issue?

It would be very handy to write following with Junit 5:

@Test
void test( @Mock ClassToMock mock, @Captor ArgumentCaptor<String> argument )
{
   verify( mock ).doStuff( argument.capture() );
}

Unfortunately, this does not work because @Captor is still not applicable to a parameter.

@TimvdLippe
Copy link
Contributor

Feel free to open a PR to implement this feature.

@TimvdLippe
Copy link
Contributor

Also please note this prior discussion on this feature which ideally requires some fixes in JUnit5: junit-team/junit5#1604

@EugenLaz
Copy link
Contributor

EugenLaz commented Oct 4, 2023

Hi @TimvdLippe.
I see that the discussion related to the JUni5 task was marked as closed due to inactivity and there are no planned changes for having an in-built solution.
Is implementing a custom resolver similar to the one proposed by nsmolenskii will be ok?
If so I'll be glad to create a PR 🙂

@TimvdLippe
Copy link
Contributor

Yes that is okay. Feel free to send us a PR!

EugenLaz pushed a commit to EugenLaz/mockito that referenced this issue Oct 5, 2023
EugenLaz pushed a commit to EugenLaz/mockito that referenced this issue Oct 5, 2023
EugenLaz pushed a commit to EugenLaz/mockito that referenced this issue Oct 5, 2023
EugenLaz pushed a commit to EugenLaz/mockito that referenced this issue Oct 5, 2023
EugenLaz pushed a commit to EugenLaz/mockito that referenced this issue Oct 5, 2023
TimvdLippe pushed a commit that referenced this issue Oct 6, 2023
Fixes #1382

Co-authored-by: yevhen lazhyntsev <yevhen.lazhyntsev@hulu.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants