Open masterpeter opened 6 years ago
Hi, you are right, this use case wasn't supported. But it was quite simple to add the code to support it, can you try to use the commit version db3a68609a? Many thanks for your report
Hi, I am trying this on version 0.8.5 but it doesn't seems to work.. Our dagger version is 2.47 My Component:
`@Component(modules = [TestModule::class])
interface TestComponent {
@Component.Builder
interface Builder {
fun build(): TestComponent
fun testModule(testModule: TestModule): TestComponent.Builder
}
@String1 fun string1() : String
@String2 fun string2() : String
}`
My Module with qualifiers:
`@Module
class TestModule {
@Provides
@String1
fun provideString1() : String = "String1"
@Provides
@String2
fun provideString2() : String = "String2"
}
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class String1
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class String2`
And test:
`@RunWith(RobolectricTestRunner::class)
class StamTest {
@get:Rule
val mockRule: DaggerMockRule<TestComponent> = DaggerMockRule(
TestComponent::class.java, TestModule()
)
@InjectFromComponent
@String1
lateinit var string1: String
@InjectFromComponent
@String2
lateinit var string2: String
@Test
fun qualifiersTest(){
println("String1: $string1, String2: $string2")
assert(string1 == "String1")
assert(string2 == "String2") //This one fails, it injects String1 instead
}
}`
Help appreciated, Moti
Hi Fabio! I'm trying to do something like this:
The second assert will fail as
a2
is again a Dog. In MyComponent I'm correctly exposing bothAnimal
with their respective qualifiers. It seems that here the first method encountered which expose the typeAnimal
will return, thus leading to the defect.This doesn't seem to happen when using DaggerMockRule setter without using
InjectFromComponent
Am I wrong? Thank you so much for your help, good job!