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
Possible race condition #3280
Comments
Hi, if you haven't yet found the root cause to your issue I would like to help take a stab at it. Based on what I read and understood so far, seems like the error message is indicating that you are mixing matchers with raw values, which is causing the problem. Have you tried providing a specific value for the getSomething method? I think the error would be resolved when you use the matchers consistently for all the arguments in your mock setup. |
Hello @jkim323 , yes I have tried that already. To keep working I just switched the positions of the mocks but i thoight that maybe this can be easily fixed by someone who knows the library.And yes you are right, the error not happens if you dont use matchers(a real value) but still happens if you use any(some.class) or eq(myString) |
Hm ok. From my own experience and what I know of, I think the problem is because you can't use argument matcher and raw values together based on the error info you provided. Therefore that is why you don't see an error when you run |
Having a mock of a service with 7 params ( I think a high number of params is somehow important ) and then mocking another one, I am getting a exception that doesnt have any sense.
If u switch the position and mock the one with a lot of params the last, the exception never happens.
If u debug the program, the exception never happens.
Here is the sample and the code and the exception:
when(myMokedService.getSomething(any(),any(),any(),any(),any(),any(),any())).thenReturn(any(Timestamp.class));
when(myAnotherMokedService.getSomething(anyString())).thenReturn(anyMockedResponse);
EXCEPTION ->
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
1 matchers expected, 2 recorded:
-> at service.automatism.AutomatismSearchExecServiceTest.givenSearchExec_whenUpdateSearchExec_then_sameSearchExecVariablesNotNull(AutomatismSearchExecServiceTest.java:121)
-> at service.automatism.AutomatismSearchExecServiceTest.givenSearchExec_whenUpdateSearchExec_then_sameSearchExecVariablesNotNull(AutomatismSearchExecServiceTest.java:123)
This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(any(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
//correct:
someMethod(any(), eq("String by matcher"));
The text was updated successfully, but these errors were encountered: