I have been working with the arch libraries from Google, but one thing that has made testing difficult is working with PagedList
.
For this example, I am usi
an easy way to achieve this, is to mock the PagedList. This fun will "convert" a list to a PagedList (in this case, we are not using the real PagedList rather just a mocked version, if you need other methods of PagedList to be implemented, add them in this fun)
fun mockPagedList(list: List): PagedList {
val pagedList = Mockito.mock(PagedList::class.java) as PagedList
Mockito.`when`(pagedList.get(ArgumentMatchers.anyInt())).then { invocation ->
val index = invocation.arguments.first() as Int
list[index]
}
Mockito.`when`(pagedList.size).thenReturn(list.size)
return pagedList
}