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
AdditionalMatchers.and() and or() swap matcher order #3331
Comments
Yes this appears to be a legitimate bug, good catch! Feel free to submit a pull request with a fix and a regression test for it! |
can i try contribute? |
@dev-jonghoonpark feel free to submit a pull request! |
hello. @TimvdLippe I found a problem and fixed the code. I think the problem was that we used stack inside ArgumentMatcherStorageImpl.java, so the order was reversed during the push/pop process. so I changed code like this (I modified it to assign the result of the popMatcher to m2 first)
Before the fix, m1 and m2 were reversed, as follows After the fix, m1 and m2 were assigned as expected, as follows I was happy to think I had fixed the bug.
I think it's correct that I'm getting an UnnecessaryStubbingException because I didn't enter the expected input. (Passed "hello", not any(MyPojo.class)) What are your thoughts? If this is the right fix, I'll raise a PR with the addition of test code for this. (Note that the Have a nice day |
I think this is normal, I didn’t write the MRE such that the mock would actually be used, but you could simply add a second call with a parameter that matches the mock, e.g.
|
…ers.or() not to swap the order of matchers
Consider the following code:
This test throws the following exception:
Debugger inspection of
And.matches()
shows thatm1
is the lambda andm2
is theInstanceOf
, as opposed to what was passed toand()
. I guess this comes fromArgumentMatcherStorageImpl#reportAnd()
andreportOr()
which popm1
beforem2
, swapping the order.This is with Mockito 5.11.0, Junit 5.10.2 and Java 11.
check that
No, it does not provide useful information (here the exception is similar to the one in argThat throws ClassCastException upon different subclass instance than for the ArgumentMatcher generic type #2268 but it could be something else like an NPE, depending on the use case)
Note that some configuration are impossible to mock via Mockito
(same as any question on stackoverflow.com)
The text was updated successfully, but these errors were encountered: