diff --git a/app/src/androidTest/java/com/example/weldy/FakeCatRepository.kt b/app/src/androidTest/java/com/example/weldy/FakeCatRepository.kt index e70acd3..35b1ff3 100644 --- a/app/src/androidTest/java/com/example/weldy/FakeCatRepository.kt +++ b/app/src/androidTest/java/com/example/weldy/FakeCatRepository.kt @@ -4,8 +4,9 @@ import androidx.paging.PagingSource import com.example.weldy.data.local.model.CatEntity import com.example.weldy.domain.model.Cat import com.example.weldy.domain.repository.CatRepository +import javax.inject.Inject -class FakeCatRepository : CatRepository { +class FakeCatRepository @Inject constructor() : CatRepository { private val fakeCatResponses = List(100) { index -> Cat("Cat$index") } diff --git a/app/src/androidTest/java/com/example/weldy/GetLocalCatsPagingSourceUseCaseTest.kt b/app/src/androidTest/java/com/example/weldy/GetLocalCatsPagingSourceUseCaseTest.kt index b2a9da8..84db1af 100644 --- a/app/src/androidTest/java/com/example/weldy/GetLocalCatsPagingSourceUseCaseTest.kt +++ b/app/src/androidTest/java/com/example/weldy/GetLocalCatsPagingSourceUseCaseTest.kt @@ -5,7 +5,6 @@ import com.example.weldy.data.local.model.CatEntity import com.example.weldy.domain.usecase.GetLocalCatsPagingSourceUseCase import com.example.weldy.data.repositoryImpl.CatRepositoryImpl import com.example.weldy.domain.repository.CatRepository -import dagger.hilt.android.testing.BindValue import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest import junit.framework.TestCase.assertEquals @@ -28,8 +27,8 @@ class GetLocalCatsPagingSourceUseCaseTest { var hiltRule = HiltAndroidRule(this) // Inject the FakeCatRepository and the use case under test - @BindValue - val catRepository: CatRepositoryImpl = mock(CatRepositoryImpl::class.java) + @Inject + lateinit var catRepository: FakeCatRepository @Inject lateinit var getLocalCatsPagingSourceUseCase: GetLocalCatsPagingSourceUseCase diff --git a/app/src/androidTest/java/com/example/weldy/GetRemotePaginatedCatsUseCaseTest.kt b/app/src/androidTest/java/com/example/weldy/GetRemotePaginatedCatsUseCaseTest.kt index 8487c6e..8ef58fe 100644 --- a/app/src/androidTest/java/com/example/weldy/GetRemotePaginatedCatsUseCaseTest.kt +++ b/app/src/androidTest/java/com/example/weldy/GetRemotePaginatedCatsUseCaseTest.kt @@ -41,8 +41,7 @@ class GetRemotePaginatedCatsUseCaseTest { var hiltRule = HiltAndroidRule(this) // Inject the CatRepository and the GetRemotePaginatedCatsUseCase - @BindValue - val catRepository: CatRepositoryImpl = mock(CatRepositoryImpl::class.java) + @Inject lateinit var getRemotePaginatedCatsUseCase: GetRemotePaginatedCatsUseCase @@ -52,7 +51,8 @@ class GetRemotePaginatedCatsUseCaseTest { private lateinit var catRemoteSource: CatRemoteSource - private lateinit var fakeCatRepository: FakeCatRepository + @Inject + lateinit var catRepository: FakeCatRepository private lateinit var mockCats: List @@ -62,7 +62,6 @@ class GetRemotePaginatedCatsUseCaseTest { // Inject the dependencies before running the tests hiltRule.inject() catRemoteSource = CatRemoteSource(getRemotePaginatedCatsUseCase) - fakeCatRepository = FakeCatRepository() mockCats = listOf( @@ -117,7 +116,7 @@ class GetRemotePaginatedCatsUseCaseTest { fun test_footer_is_visible() = runTest { // Get the Flow of PagingData from the ViewModel under test val pager = Pager(PagingConfig(pageSize = 10)) { - FakeCatPagingSource(fakeCatRepository) + FakeCatPagingSource(catRepository) } val flow: Flow> = pager.flow diff --git a/app/src/androidTest/java/com/example/weldy/di/TestCatModule.kt b/app/src/androidTest/java/com/example/weldy/di/TestCatModule.kt index 68060a8..5bebb64 100644 --- a/app/src/androidTest/java/com/example/weldy/di/TestCatModule.kt +++ b/app/src/androidTest/java/com/example/weldy/di/TestCatModule.kt @@ -1,4 +1,3 @@ -/* package com.example.weldy.di import com.example.weldy.FakeCatRepository @@ -15,4 +14,4 @@ object TestCatModule { @Provides @Singleton fun provideFakeCatRepository(): CatRepository = FakeCatRepository() -}*/ +}