This's a method of my `LocalDataSource`:
override fun findPosts(pageSize: Int): Flow<PagingData<Post>> {
return Pager(
config = PagingConfig(pageSize = pageSize, enablePlaceholders = false),
pagingSourceFactory = { postsDao.findPosts() }
).flow.map { pagingData ->
pagingData.map(PostEntity::toPost)
}
}
findPosts
is a Room method that returns
PagingSource<Int, PostEntity>
and
I'm exposing
Flow<PagingData<Post>>
since I'm unable to map a
PagingSource<Int, PostEntity>
to a
PagingSource<Int, Post>
.
I have a problem with both creating a fake of
PagingData
and with testing it.
I need to create a fake of
LocalDataSource
where I replace the method mentioned above with a fake version of it, the way to do that seems to be to create a
PagingSource
just for testing, which is more code than the actual code being tested.
The other problem is testing the
PagingData
flow, there seems to be no way to know what data
PagingData
contains, so even if I create a
PagingSource
, how do I know it contains the correct data and delivers them correctly?