Skip to content

Instantly share code, notes, and snippets.

@deepakazad
Last active June 28, 2017 03:37
Show Gist options
  • Save deepakazad/02314dc72b799069bb3a016a2adf1150 to your computer and use it in GitHub Desktop.
Save deepakazad/02314dc72b799069bb3a016a2adf1150 to your computer and use it in GitHub Desktop.
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