Last active
June 28, 2017 03:37
-
-
Save deepakazad/02314dc72b799069bb3a016a2adf1150 to your computer and use it in GitHub Desktop.
RxJava: Observable to Single
This file contains hidden or 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
@Test | |
public void testEmptyObservableToSingle() { | |
Observable.empty() | |
.flatMapSingle(o -> Single.just("result")) | |
.test() | |
.assertValueCount(0) | |
.assertNoErrors(); | |
//Should there be an error? | |
} |
This file contains hidden or 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
@Test | |
public void testEmptyObservableToSingleExplanation() { | |
Observable.just("item1", "item2") | |
.flatMapSingle(o -> Single.just("result")) | |
.test() | |
.assertValueCount(2) | |
.assertValues("result", "result") | |
.assertNoErrors(); | |
} |
This file contains hidden or 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
@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