From 9f5c4360b1011dde44d356be04567f7245377276 Mon Sep 17 00:00:00 2001 From: "Wei.He" Date: Fri, 26 Jan 2024 15:46:00 +0800 Subject: [PATCH] chore: Add :core:data-test module for replacing fake objects during Testing. --- core/data-test/.gitignore | 1 + core/data-test/build.gradle.kts | 14 ++++++++ core/data-test/src/main/AndroidManifest.xml | 4 +++ .../data/test/AlwaysOnlineNetworkMonitor.kt | 12 +++++++ .../picquest/core/data/test/TestDataModule.kt | 33 +++++++++++++++++++ settings.gradle.kts | 1 + 6 files changed, 65 insertions(+) create mode 100644 core/data-test/.gitignore create mode 100644 core/data-test/build.gradle.kts create mode 100644 core/data-test/src/main/AndroidManifest.xml create mode 100644 core/data-test/src/main/java/com/wei/picquest/core/data/test/AlwaysOnlineNetworkMonitor.kt create mode 100644 core/data-test/src/main/java/com/wei/picquest/core/data/test/TestDataModule.kt diff --git a/core/data-test/.gitignore b/core/data-test/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/core/data-test/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core/data-test/build.gradle.kts b/core/data-test/build.gradle.kts new file mode 100644 index 0000000..ffaa2f3 --- /dev/null +++ b/core/data-test/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + alias(libs.plugins.pq.android.library) + alias(libs.plugins.pq.android.hilt) +} + +android { + namespace = "com.wei.picquest.core.data.test" +} + +dependencies { + api(projects.core.data) + + implementation(libs.hilt.android.testing) +} diff --git a/core/data-test/src/main/AndroidManifest.xml b/core/data-test/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a5918e6 --- /dev/null +++ b/core/data-test/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/core/data-test/src/main/java/com/wei/picquest/core/data/test/AlwaysOnlineNetworkMonitor.kt b/core/data-test/src/main/java/com/wei/picquest/core/data/test/AlwaysOnlineNetworkMonitor.kt new file mode 100644 index 0000000..b2fb4e1 --- /dev/null +++ b/core/data-test/src/main/java/com/wei/picquest/core/data/test/AlwaysOnlineNetworkMonitor.kt @@ -0,0 +1,12 @@ +package com.wei.picquest.core.data.test + +import com.wei.picquest.core.data.utils.NetworkMonitor +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOf +import javax.inject.Inject + +class AlwaysOnlineNetworkMonitor +@Inject +constructor() : NetworkMonitor { + override val isOnline: Flow = flowOf(true) +} diff --git a/core/data-test/src/main/java/com/wei/picquest/core/data/test/TestDataModule.kt b/core/data-test/src/main/java/com/wei/picquest/core/data/test/TestDataModule.kt new file mode 100644 index 0000000..40462eb --- /dev/null +++ b/core/data-test/src/main/java/com/wei/picquest/core/data/test/TestDataModule.kt @@ -0,0 +1,33 @@ +package com.wei.picquest.core.data.test + +import com.wei.picquest.core.data.di.DataModule +import com.wei.picquest.core.data.repository.DefaultSearchImagesRepository +import com.wei.picquest.core.data.repository.DefaultSearchVideosRepository +import com.wei.picquest.core.data.repository.DefaultUserDataRepository +import com.wei.picquest.core.data.repository.SearchImagesRepository +import com.wei.picquest.core.data.repository.SearchVideosRepository +import com.wei.picquest.core.data.repository.UserDataRepository +import com.wei.picquest.core.data.utils.NetworkMonitor +import dagger.Binds +import dagger.Module +import dagger.hilt.components.SingletonComponent +import dagger.hilt.testing.TestInstallIn + +@Module +@TestInstallIn( + components = [SingletonComponent::class], + replaces = [DataModule::class], +) +interface TestDataModule { + @Binds + fun bindsSearchImagesRepository(searchImagesRepository: DefaultSearchImagesRepository): SearchImagesRepository + + @Binds + fun bindsSearchVideosRepository(searchVideosRepository: DefaultSearchVideosRepository): SearchVideosRepository + + @Binds + fun bindsNetworkMonitor(networkMonitor: AlwaysOnlineNetworkMonitor): NetworkMonitor + + @Binds + fun bindsUserDataRepository(userDataRepository: DefaultUserDataRepository): UserDataRepository +} diff --git a/settings.gradle.kts b/settings.gradle.kts index a64eec7..3736e5d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,6 +23,7 @@ include(":core:designsystem") include(":core:testing") include(":core:common") include(":core:data") +include(":core:data-test") include(":core:domain") include(":core:model") include(":core:network")