Я пытаюсь получить экземпляр OkHttp от TestComponent, у меня есть эта настройка
@Singleton
@Component(
modules = [
AndroidInjectionModule::class,
RetrofitModule::class]
)
interface TestAppComponent : AndroidInjector<TestApp> {
@Component.Factory
interface Factory {
fun create(@BindsInstance application: TestApp): TestAppComponent
}
}
И тогда мой TestApp
open class TestApp : App() {
override fun onCreate() {
super.onCreate()
DaggerTestAppComponent.factory()
.create(this)
.inject(this)
}
}
Работает, но вещь находится на моем AbstractBaseTest Я не могу использовать
@Inject
lateinit var client : OkHttpClient
Даже если у меня есть метод предоставляет для этого в моем RetrofitModule
@Provides
@Singleton
fun provideOkHttpClient(
httpLoggingInterceptor: HttpLoggingInterceptor,
headersInterceptor: HeadersInterceptor,
errorInterceptor: ErrorInterceptor
): OkHttpClient = OkHttpClient()
.newBuilder()
.addInterceptor(httpLoggingInterceptor)
.addInterceptor(headersInterceptor)
.addInterceptor(errorInterceptor)
.build()
И ошибка
kotlin.UninitializedPropertyAccessException: lateinit property client has not been initialized
Что мне не хватает?
Есть ответ на этот вопрос, но я не могу воспроизвести это Как переопределить модуль / зависимость в модульном тесте с Dagger 2.0?