-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
ArgumentMatchers not working for Mockito.mockStatic #2497
Comments
Note: if I remove ArgumentMatchers no exceptions are thrown. |
@nickmafra try using matchers for all the params (see the added eq matcher below): var mockedRequestClass = Mockito.mockStatic(RequestClass.class);
mockedRequestClass.when(() -> RequestClass.sendRequest(eq(mockedUrl), any(), any())).thenReturn(null); When using traditional mocks, it'll tell you to use matchers for all the params when at least one of them uses a matcher. My hunch is it's the same for MockedStatic and the exception you're getting is misleading because it swallowed the root cause of the issue. |
Sounds like we should update |
Hi @TimvdLippe , I think the issue comes from here: The validation is happening but ignored. Not sure why, but this could fix it if we want to keep the try {
verification.apply();
} catch (MockitoException exception) {
throw exception;
} catch (Throwable ignored) {
} What do you think? |
In my case, I had to pass Integer. |
When I do a mockStatic with argument matchers like this:
Mockito throws the following exception:
org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'.
How can I use argument matchers with Mockito.mockStatic? Shouldn't that be possible?
The text was updated successfully, but these errors were encountered: