android - How correctly test if subscriber is called with correct data in onNext() (RxJava2) -
i test method:
void updateavailablescreens() { safiecam.availablecameras() .flatmap(this::getavailablescreensforcameras) // causing failure .observeon(schedulers.mainthread()) .subscribe( screens -> { view.setavailablepagesonviewpager(screens); view.setavailablepagesonbottomsheet(screens); }, timber::e ); }
with test (so giving known data, expect calling view expected enum list):
@test public void widgetsshouldgetallscreens() { when(camera.availablecameras()).thenreturn( observable.just(arrays.aslist( safiecam.cameratype.selfie, safiecam.cameratype.rear))); testedvppresenter.updateavailablescreens(); list<viewpagerview.pages> pages = arrays.aslist( viewpagerview.pages.selfie, viewpagerview.pages.rear_camera, viewpagerview.pages.login); verify(view).setavailablepagesonviewpager(pages); verify(view).setavailablepagesonbottomsheet(pages); }
but when observeon uncommented test fail due 0 interactions view
, otherwise succed.
needed info: schedulers
interface wrapper, , called schedulers mocked on tests testscheduler.
question: doing wrong here? if correct approach?
i misused testscheduler, because didn't call
testscheduler.triggeractions()
after using test scheduler (in case after testedvppresenter.updateavailablescreens()
)
so events queued, without execution.
Comments
Post a Comment