Assert value comparison failed for TestObserver

354 Views Asked by At

I have a fake API service that will mock the failure. So when it calls through paging source I should be getting PagingSource.LoadResult.Error of the type returned by API service. This is my test function

        @Test
        fun `users paging source load - failure - error`() {
            val errorMessage = "404"
            val error = RuntimeException(errorMessage, Throwable())
            val expectedResult = PagingSource.LoadResult.Error<Int, UserRemote>(error)
            fakeGitHubService.failureMessage = errorMessage

            userPagingSource.loadSingle(
                PagingSource.LoadParams.Refresh(
                    key = 0,
                    loadSize = 1,
                      placeholdersEnabled = false
                )
            ).test()
                .await()
                .assertComplete()
                .assertValueCount(1)
                .assertValue{it == expectedResult}

            fakeGitHubService.failureMessage = null
        }

It failed with this error

    java.lang.AssertionError: Value not present (latch = 0, values = 1, errors = 0, completions = 1)

This is the implementation of Fake Service

class FakeUserSearchService : UserSearchService {
.
.
    override fun getUsers(query: String, pageSize: Int, page: Int): Single<SearchUserResponse> {
        failureMessage?.let {
            return Single.error(RuntimeException(failureMessage, Throwable()))
        }

        return Single.just(SearchUserResponse(findBreeds(page, pageSize), models.size))
    }
.
.

}
0

There are 0 best solutions below