Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :core:data-test module for replacing fake objects during Testing #86

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/data-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
14 changes: 14 additions & 0 deletions core/data-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
alias(libs.plugins.at.android.library)
alias(libs.plugins.at.android.hilt)
}

android {
namespace = "com.wei.amazingtalker.core.data.test"
}

dependencies {
api(project(":core:data"))

implementation(libs.hilt.android.testing)
}
4 changes: 4 additions & 0 deletions core/data-test/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wei.amazingtalker.core.data.test

import com.wei.amazingtalker.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<Boolean> = flowOf(true)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.wei.amazingtalker.core.data.test

import com.wei.amazingtalker.core.data.di.DataModule
import com.wei.amazingtalker.core.data.repository.DefaultTeacherScheduleRepository
import com.wei.amazingtalker.core.data.repository.DefaultUserDataRepository
import com.wei.amazingtalker.core.data.repository.ProfileRepository
import com.wei.amazingtalker.core.data.repository.TeacherScheduleRepository
import com.wei.amazingtalker.core.data.repository.UserDataRepository
import com.wei.amazingtalker.core.data.repository.fake.FakeProfileRepository
import com.wei.amazingtalker.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 bindsProfileRepository(
profileRepository: FakeProfileRepository,
): ProfileRepository

@Binds
fun bindsTeacherScheduleRepository(
teacherScheduleRepository: DefaultTeacherScheduleRepository,
): TeacherScheduleRepository

@Binds
fun bindsNetworkMonitor(
networkMonitor: AlwaysOnlineNetworkMonitor,
): NetworkMonitor

@Binds
fun bindsUserDataRepository(
userDataRepository: DefaultUserDataRepository,
): UserDataRepository
}
4 changes: 3 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ include(":core:designsystem")
include(":core:testing")
include(":core:datastore")
include(":core:datastore-test")
include(":core:data-test")

include(":ui-test-hilt-manifest")

include(":feature:login")
include(":feature:teacherschedule")
include(":feature:contactme")
include(":ui-test-hilt-manifest")
include(":feature:home")
Loading