ArgumentMatchers support for @NonNull / Kotlin non-null
See original GitHub issueHello folks,
There is an issue when using ArgumentsMatcher.eq() method with either:
- A Java @NonNull annotated param
- A Kotlin non-null param
Example (in kotlin):
- Let’s say you have a method:
doSomething(test: String) {...}
- When trying to do:
Mockito.verify(mock).doSomething(ArgumentMatchers.eq("toto"))
At runtime the test is going to fail with message:
java.lang.IllegalStateException: ArgumentMatchers.eq("toto") must not be null
Is there a way to return NonNull objects from the eq method?
Thank you in advance 😃
Issue Analytics
- State:
- Created 6 years ago
- Reactions:40
- Comments:19 (8 by maintainers)
Top Results From Across the Web
ArgumentMatchers.any must not be null - Stack Overflow
Getting matchers to work with Kotlin can be a problem. If you have a method written in kotlin that does not take a...
Read more >ArgumentMatchers (Mockito 2.7.19 API) - javadoc.io
Matches any object of given type, excluding nulls. static boolean, anyBoolean(). Any boolean or non-null Boolean. static byte ...
Read more >Using mockito with kotlin - Derek Wilson
this is the same problem as we found with argument matchers. The sendData() method is written in Kotlin and the second parameter cannot...
Read more >Null safety - Kotlin
Nullable types and non-null types. Kotlin's type system is aimed at eliminating the danger of null references, also known as The Billion ...
Read more >Java static code analysis: "@NonNull" values should not be ...
Mockito argument matchers should be used on all parameters ... Fields, parameters and return values marked @NotNull , @NonNull , or @Nonnull are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
How is this still an outstanding issue?
The
eq
problem can be addressed quite easily. A different name was only chose to not get into import hell.