-
Notifications
You must be signed in to change notification settings - Fork 585
-
Notifications
You must be signed in to change notification settings - Fork 585
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
Mocking whenNew using withAnyArguments does not match null arguments #891
Comments
For what it's worth I reproduced this problem with the latest HEAD of branch When an object has multiple constructors, this code in withAnyArguments generates matchers for the first constructor and matchers for the remaining constructors are generated somewhere else (during the So if the constructor you need mocked happens to be the first one the |
Fix for powermock#891 which prevented null arguments from matching with generated constructor matchers.
…ments Fixes construcotr generated matchers to include allowance for null arguments.
…ments Fixes generated matchers for constructors to include allowance for null arguments.
…ments Fixes generated matchers for constructors to include allowance for null arguments.
…uments Fixes generated matchers for constructors to include allowance for null arguments.
Fixes generated matchers for constructors to include allowance for null arguments.
Using:
powermock-module-junit4 2.0.0-beta.5
powermock-api-mockito2 2.0.0-beta.5
mockito-core 2.16.0
I am having trouble using the
whenNew(Class).withAnyArguments()
when one of those arguments isnull
in the tested code. For example, the following test case is failing for me:This test example should pass but because the
withAnyArguments()
generates incorrect constructor argument matchers, thenew
returnsnull
and the assertion fails.I have tried to examine this under the debugger and I am able to determine that the the "expected" matches are getting generated as:
[any(StatusLine.class), any(ReasonPhraseCatalog.class), any(Locale.class)
] which causes it to not match the third null parameter, since null is not instanceof(Locale.class).I'm having a hard time figuring out where it generated the list of argument matchers though to find the bug.
The text was updated successfully, but these errors were encountered: