mockito / mockito-kotlin

Using Mockito with Kotlin
MIT License
3.1k stars 200 forks source link

How to Mock List.forEach #385

Open ppamorim opened 4 years ago

ppamorim commented 4 years ago

First thing: I know it's incorrect to mock lists.

I am experiencing issues to iterate in an object RealmList<Foo> using this mock library. You can see more of this problem here: https://stackoverflow.com/questions/63042724/how-to-mock-kotlins-list-foreach

I have been trying to call the native function but I am not sure what signature should be, I tried this below but no success:

doCallRealMethod().`when`(mockedList).forEach(any())

The code above is based on this one, especially in this line: https://github.com/realm/realm-java/blob/master/examples/unitTestExample/src/test/java/io/realm/examples/unittesting/ExampleActivityTest.java#L167

There are some conflicts in this implementation, especially with high order functions. Is there anything I can do sort this?