Last active
November 10, 2015 22:53
-
-
Save trevorrjohn/7766f0c4c988c687ae44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service.getRepo("123") | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe( | |
repo -> | |
repoView.setText(repo.getName()), | |
e -> { /* show some error message */ } | |
); | |
Observable mockObservable = mock(Observable.class); | |
when(service.getRepo(anyString())) | |
.thenReturn(mockObservable); | |
when(mockObservable.subscribeOn(any())) | |
.thenReturn(mockObservable); | |
when(mockObservable.observeOn(any())) | |
.thenReturn(mockObservable); | |
ArgumentCaptor<Func1> functCaptor = | |
ArgumentCaptor.forClass(Func1.class); | |
when(mockObservable.map(functCaptor.capture())) | |
.thenReturn(mockObservable); | |
ArugmentCaptor<Action1> onNextCaptor = | |
ArgumentCaptor.forClass(Action1.class); | |
ArugmentCaptor<Action1> onErrorCaptor = | |
ArgumentCaptor.forClass(Action1.class); | |
activity.onCreate(null); | |
verify(mockObservable) | |
.subscribe( | |
onNextCaptor.capture(), | |
onErrorCaptor.capture() | |
); | |
functCaptor.getValue() | |
.call(new Repo("WTF!?")); | |
Action1 onNext = onNextCaptor.getValue(); | |
onNext.call(new Repo("WTF!?")); | |
assertThat(repoView).hasText("WTF!?") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment