Ariana
12/27/2019, 5:31 PMMaybe.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?Paul Woitaschek
12/28/2019, 9:53 AMAriana
12/30/2019, 4:27 PMfromCallable
in the test?Paul Woitaschek
12/30/2019, 4:30 PMval stuffList1 = listOf(1,2,3)
val stuffList2 = listOf(4,5,6)
var invocation = 0
Single.fromCallable {
when(++invocation){
1 -> stuffList1
2 -> stuffList2
else -> error("Didn't answer invocation $invocation")
}
}
Ariana
12/30/2019, 4:31 PM