Hey all, I’m trying to unit test using Robolectric and am running into a weird scenario
Here’s the code block I’m executing:
Maybe.just(list)
.flatMapSingle { repository.getStuffList(id) }
.map { stuffList -> stuffList.filter { stuff -> list.contains(stuff) } }
.flatMapCompletable { stuffAfterFilter ->
secondRepository.doThing(stuffAfterFilter)
.doOnError { Completable.error(IllegalStateException("failure")) }
.andThen { repository.deleteStuff(stuffAfterFilter) }
}
.andThen(repository.getStuffList(id))
What’s the best way to have each call to
repository.getStuffList(id)
return different items when they’re called?
Right now I’ve got order of operations setup in my test (which has worked in the past), but now the first time the method is called it’s returning
stuffList2
instead of
stuffList1
whenever(repository.getStuffList("id")).thenReturn(Single.just(stuffList1))
whenever(secondRepository.doThing(any())).thenReturn(Completable.complete())
whenever(repository.deleteStuff(any())).thenReturn(Completable.complete())
whenever(repository.getStuffList("id")).thenReturn(Single.just(stuffList2))
Am I on the right path here?