Parameter specified as non-null is null when using Mokito anyObject() on Kotlin function

By default Kotlin classes and members are final. Mockito cannot mock final classes or methods. Thus when you write:

verify(injectedObject).settingDependentObject(anyObject())

the real implementation is called which requires non null argument.

To fix that either open your class and method or, even better, change SimpleClass to accept an interface as its constructor argument and mock the interface instead.

Tags:

Mockito

Kotlin