I’m implemented the Paging 3 library and I’d like ...
# test
m
I’m implemented the Paging 3 library and I’d like to test my repository. I’ve seen the Paging 3 testing webpage but there’s only theory about the repository tests. My repository looks like this:
Copy code
class RepositoriesRepositoryImpl @Inject constructor(
    @IoCoroutineDispatcher private val ioCoroutineDispatcher: CoroutineDispatcher,
    private val service: GithubService,
    private val database: RepositoriesDatabase
) : RepositoriesRepository {
    @OptIn(ExperimentalPagingApi::class)
    override suspend fun fetchRepositories() = withContext(ioCoroutineDispatcher) {
        return@withContext Pager(config = PagingConfig(
            pageSize = NETWORK_PAGE_SIZE, enablePlaceholders = false
        ),
            remoteMediator = GithubRemoteMediator(ioCoroutineDispatcher, service, database),
            pagingSourceFactory = { database.repositoriesDao().allRepositories() }).flow
    }

    companion object {
        const val NETWORK_PAGE_SIZE = 10
    }
}
And this is my test class:
Copy code
@ExperimentalCoroutinesApi
class RepositoriesRepositoryTest {
    private lateinit var sut: RepositoriesRepository
    private val testDispatcher = UnconfinedTestDispatcher()
    private val fakeGithubService: GithubService = mock {
        onBlocking { fetchRepos(any(), any()) } doSuspendableAnswer {
            Response.success((listOf()))
        }
    }
    private val inMemoryDatabase = Room.inMemoryDatabaseBuilder(
        ApplicationProvider.getApplicationContext(), RepositoriesDatabase::class.java
    ).build()

    @Before
    fun setup() {
        sut = RepositoriesRepositoryImpl(testDispatcher, fakeGithubService, inMemoryDatabase)
    }

    @Test
    fun test1() = runTest {
        sut.fetchRepositories().test {
            val item: PagingData<Repository> = awaitItem()
            assertNull(item)
        }
    }
}
What I’m trying is to assert the content of the
PagingData
, just to see that it contains whatever number repository I’m passing in the test expectation. How could I do this? Thanks!