mockito / mockito-kotlin

Using Mockito with Kotlin
MIT License
3.11k stars 202 forks source link

mock fails with MissingMethodInvocationException #323

Closed mehdiyari closed 5 years ago

mehdiyari commented 5 years ago

hi i use the mockito-kotlin:2.1.0 in my android-kotlin project but when i try to mock object mockito fails with this Exception ` org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'. For example: when(mock.getArticles()).thenReturn(articles);

Also, this error might show up because:

  1. you stub either of: final/private/equals()/hashCode() methods. Those methods cannot be stubbed/verified. Mocking methods declared on non-public parent classes is not supported.
  2. inside when() you don't call method on mock but on some other object. ` for all classes mokito-kotlin fails with above message. i searched about this but its no result.
bohsen commented 5 years ago

@mehdiyari It could be multiple things.

  1. You're mocking a final class/method without 'inline-mock-maker' or 'AllOpen plugin' enabled
  2. You're not using 'Mockito-kotlin' correctly as the stacktrace might indicate

Could you show some code, as to indicate where the problem might be?

mehdiyari commented 5 years ago

@bohsen event when iam use mokito-kotlin examples, test throw this error my calass is not final but i have no idea what is 'AllOpen plugin' I will be grateful if you provide me an example with mokito-kotlin that works properly

nhaarman commented 5 years ago

Closing this for lack of a reproducible example. If this is still an issue, please create a new issue with a Minimal, Verifiable and Reproducible example.