fabioCollini / DaggerMock

A JUnit rule to easily override Dagger 2 objects
Apache License 2.0
1.16k stars 96 forks source link

Provided Named Dependencies #84

Closed krazykira closed 5 years ago

krazykira commented 6 years ago

How to use the provides method to replace named dependencies inside the dependency graph ?

e.g

provides(
                @Named("Auth") OkHttpClient::class.java, // throws compile time error
                MockHttpClient.getClient())

Is there any other way to do this ?

fabioCollini commented 6 years ago

Not now, but it can be a useful feature. I'll try to implement it for the next release, thanks for the suggestion

fabioCollini commented 6 years ago

Hi @krazykira, I have implemented this feature in the last commit 383fa8003e, can you try it using this commit as DaggerMock version?

In your example the syntax to use should be this:

 provides<OkHttpClient>("Auth", MockHttpClient.getClient())

Let me know if it works!

olegivo commented 5 years ago

@fabioCollini, it is work for me. Thank you! Will you include this feature into next release and how soon?

fabioCollini commented 5 years ago

Released right now: https://jitpack.io/#fabioCollini/DaggerMock/0.8.5

krazykira commented 5 years ago

thanks. i will try it and let you know if i run into a problem