"", emptyList()), Cat("2", "", emptyList()), Cat("3", "", emptyList()) ) private val repository: CatRepository = mock { onBlocking { cats(any(), any()) } doReturn Result.success(mockCats) } private val useCase: CatUseCase by lazy { CatUseCase(repository) } private val firstPage = 1 private val mockLoadParams by lazy { PagingSource.LoadParams.Refresh( key = firstPage, loadSize = useCase.limit, placeholdersEnabled = true ) } @Test @Throws(Exception::class) fun loadResult_success() = runBlocking { useCase.cats().load(mockLoadParams).let { assertTrue { it is PagingSource.LoadResult.Page } (it as PagingSource.LoadResult.Page).let { result -> result.itemsBefore assertEquals(result.data.size, mockCats.size) assertEquals(result.data.first().id, "1") assertNotNull(result.nextKey) assertEquals(result.nextKey, firstPage + 1) assertEquals(result.prevKey, firstPage - 1) } } } @Test @Throws(Exception::class) fun loadResult_failure() = runBlocking { whenever(repository.cats(any(), any())) doReturn Result.failure(mock<HttpException>()) useCase.cats().load(mockLoadParams).let { assertTrue { it is PagingSource.LoadResult.Error } assertTrue { (it as PagingSource.LoadResult.Error).throwable is HttpException } } } }