Skip to content

Commit

Permalink
Merge pull request #88 from azrael8576/feat/data-test-module
Browse files Browse the repository at this point in the history
Add :core:data-test module for replacing fake objects during Testing
  • Loading branch information
azrael8576 authored Jan 26, 2024
2 parents 1ee666f + 9f5c436 commit cab14ce
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
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.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)
}
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,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<Boolean> = flowOf(true)
}
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit cab14ce

Please sign in to comment.