Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RxJava: Observable to Single
@Test
public void testEmptyObservableToSingle() {
Observable.empty()
.flatMapSingle(o -> Single.just("result"))
.test()
.assertValueCount(0)
.assertNoErrors();
//Should there be an error?
}
@Test
public void testEmptyObservableToSingleExplanation() {
Observable.just("item1", "item2")
.flatMapSingle(o -> Single.just("result"))
.test()
.assertValueCount(2)
.assertValues("result", "result")
.assertNoErrors();
}
@Test
public void testObservableToSingle() {
Observable.just("item1", "item2")
.single("result")
.test()
.assertError(IllegalArgumentException.class)
.assertErrorMessage("Sequence contains more than one element!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment