This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DefaultDataRepositoryTest { | |
@Inject | |
lateinit var dataRepository: DefaultDataRepository | |
@Inject | |
lateinit var remoteDataSource: DataSource | |
@Before | |
fun setup() { | |
val component: TestAppComponent = DaggerTestAppComponent.factory() | |
.create(TestBaseApplication()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
compileSdkVersion 30 | |
buildToolsVersion "30.0.2" | |
defaultConfig { | |
applicationId "com.example.dagger" | |
minSdkVersion 16 | |
targetSdkVersion 30 | |
versionCode 1 | |
versionName "1.0" | |
multiDexEnabled true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomTestRunner : AndroidJUnitRunner() { | |
override fun newApplication(cl: ClassLoader?, name: String?, context: Context?): Application { | |
return super.newApplication(cl, TestBaseApplication::class.java.name, context) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestBaseApplication : BaseApplication() { | |
override fun initializeDaggerComponent(): AppComponent { | |
val component: TestAppComponent = DaggerTestAppComponent.factory() | |
.create(this) | |
component.inject(this) | |
return component | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Component( | |
modules = [ | |
AndroidInjectionModule::class, NetworkModule::class, | |
TestAppModule::class, AppModuleBinds::class, | |
ViewModelBuilderModule::class, ActivityBuildersModule::class | |
] | |
) | |
interface TestAppComponent : AppComponent { | |
@Component.Factory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
class TestAppModule { | |
@Singleton | |
@Provides | |
fun provideTasksRemoteDataSource( | |
apiService: ApiService | |
): DataSource { | |
return mockk() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DefaultDataRepositoryTest { | |
private val remoteDataSource: DataSource = mockk() | |
private lateinit var dataRepository: DefaultDataRepository | |
@Before | |
fun setup() { | |
dataRepository = DefaultDataRepository(remoteDataSource) | |
} | |
@ExperimentalCoroutinesApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class BaseApplication : DaggerApplication() { | |
override fun applicationInjector(): AndroidInjector<out DaggerApplication> { | |
return initializeDaggerComponent() | |
} | |
open fun initializeDaggerComponent(): AppComponent { | |
val component: AppComponent = DaggerAppComponent.factory() | |
.create(this) | |
component.inject(this) | |
return component | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
@Component( | |
modules = [ | |
AndroidInjectionModule::class, NetworkModule::class, | |
AppModule::class, AppModuleBinds::class, | |
ViewModelBuilderModule::class, ActivityBuildersModule::class | |
] | |
) | |
interface AppComponent : AndroidInjector<DaggerApplication> { | |
@Component.Factory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
class NetworkModule { | |
@Singleton | |
@Provides | |
fun provideHttpLoggingInterceptor(): HttpLoggingInterceptor { | |
return HttpLoggingInterceptor() | |
.setLevel(HttpLoggingInterceptor.Level.BODY) | |
} | |
@Singleton | |
@Provides |