I am trying to test a function where it uses `List...
# announcements
I am trying to test a function where it uses
and I setup the
of the mocked list and populated it. I thought it could be enough, but I am getting NPE.
Copy code
I noticed that
creates a new arraylist by doing
val list = ArrayList<T>(n)
. could be the problem here?
Why not just create a list containing the values your test needs?
Then you don’t need to fiddle around with Mockito at all
I can’t, there is no init for this list
of course the code above is just an example
What do you mean, “there is no init”.
How does the code under test get passed the mocked list?
“There is no easily mockable initializer”
Instead of passing it a mocked list, pass it a List created by the listOf function
I prefer to ditch
So first to the NPE Problem: I'm not exactly sure, but I guess the problem is that
calls the
property of your mock, which might return null. But what exactly keeps you from just creating an instance of RealmList with one of the constructors that are documented on the page you posted?
on a completely different note: when using mockito with kotlin, I suggest you use the mockito-kotlin lib. That helps you avoiding the backticks each time you mock a function and it also avoids some errors with non-null parameters ans mockito matchers. Or just fully replace mockito with mockk
👍 1