I’m trying to test my repo which looks something l...
# mockk
v
I’m trying to test my repo which looks something like this. The issue is I’m not quite sure how to deal with the FirebaseInstanceId. Is this something I can mock, if so how would I do that?
Copy code
class Repository(private val service: RetrofitService) {

    suspend fun sendToken() {
        val result = FirebaseInstanceId.getInstance().instanceId.await()
        service.sendTokenToServer(result.token)
    }

}
t
https://mockk.io/ -> look for
mockkStatic
😉
o
Isn't it better to provide Firebase instance as a constructor parameter? Mocking static is the evil path
💯 1
t
I agree, I assumed it was a dummy example and it might not be straight forward to do proper DI. if it was for me, I would remove mockkstatic, though it is needed for extension function I guess
👍 1
v
So you’re saying inject the firebase instance and mockStatic the await function.
k
That’s what I would do, too.
g
I wouldn't mock static await function, looks as very bad idea in general (and even note sure why do you need this, you can just return own Task instance). And wouldn't even inject FirebaseInstanceId, just abstract it and have own interface that provides instance id This approach not only allows you to test it, doesn't require mocking at all, but also follows separation of concerns principle