Ahmed Mourad
05/26/2021, 4:19 PMPagingSource
and implementing it in the presentation layer is far from ideal.Ahmed Mourad
05/26/2021, 4:26 PMItemsPager
interface in the domain layer that the PagingSource
also implements and have a mapper that maps ItemPager
to PagingSource
, but I've never seen that done anywhere and it would also mean that I don't get to use Room's Paging support.Dustin Lam
05/26/2021, 4:33 PMDustin Lam
05/26/2021, 4:37 PMAnshulupadhyay03
05/27/2021, 6:07 AMAhmed Mourad
05/28/2021, 7:28 PMFlow<PagingData<..>>
, because it doesn't seem to be possible to map the items of a PagingSource
directly.
However, this thing doesn't seem to be testable, whatsoever, if your PagingSource
is created by Room. Is that the case?Dustin Lam
05/28/2021, 8:42 PMDustin Lam
05/28/2021, 8:43 PMDustin Lam
05/28/2021, 8:44 PMDustin Lam
05/28/2021, 8:44 PMAhmed Mourad
05/28/2021, 10:42 PMoverride 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?Ahmed Mourad
05/28/2021, 10:44 PMDustin Lam
05/28/2021, 10:46 PMDustin Lam
05/28/2021, 10:47 PM