Skip to content

Commit

Permalink
bug fix FakeCatRepository for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mojtaba Shirkhani authored and Mojtaba Shirkhani committed Sep 8, 2024
1 parent 23f0aa4 commit 2dd669f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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") }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<CatResponse>

Expand All @@ -62,7 +62,6 @@ class GetRemotePaginatedCatsUseCaseTest {
// Inject the dependencies before running the tests
hiltRule.inject()
catRemoteSource = CatRemoteSource(getRemotePaginatedCatsUseCase)
fakeCatRepository = FakeCatRepository()


mockCats = listOf(
Expand Down Expand Up @@ -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<PagingData<Cat>> = pager.flow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*
package com.example.weldy.di

import com.example.weldy.FakeCatRepository
Expand All @@ -15,4 +14,4 @@ object TestCatModule {
@Provides
@Singleton
fun provideFakeCatRepository(): CatRepository = FakeCatRepository()
}*/
}

0 comments on commit 2dd669f

Please sign in to comment.