question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ArgumentMatchers support for @NonNull / Kotlin non-null

See original GitHub issue

Hello 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:closed
  • Created 6 years ago
  • Reactions:40
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

105reactions
capezzbrcommented, Jun 8, 2019

How is this still an outstanding issue?

23reactions
lemartincommented, Nov 24, 2017

The eq problem can be addressed quite easily. A different name was only chose to not get into import hell.

fun <T : Any> safeEq(value: T): T = eq(value) ?: value
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found