Java Code Examples for io.reactivex.Observable#blockingLast()

The following examples show how to use io.reactivex.Observable#blockingLast() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HangmanTest.java    From java with MIT License 6 votes vote down vote up
@Ignore("Remove to run test")
@Test
public void gameInProgress() {
    Observable<Output> result = hangman.play(
        Observable.fromArray("secret"),
        Observable.fromArray("a", "e", "o", "s"));
    Output last = result.blockingLast();
    assertEquals("se__e_", last.discovered);
    assertEquals(Set.of("e", "s"), last.guess);
    assertEquals(Set.of("a", "o"), last.misses);
    assertEquals(
        Arrays.asList(
            Part.HEAD,
            Part.BODY),
        last.parts);
    assertEquals(Status.PLAYING, last.status);
}
 
Example 2
Source File: HangmanTest.java    From java with MIT License 6 votes vote down vote up
@Ignore("Remove to run test")
@Test
public void lostGame() {
    Observable<Output> result = hangman.play(
        Observable.fromArray("secret"),
        Observable.fromArray("a", "b", "c", "d", "e", "f", "g", "h"));
    Output last = result.blockingLast();
    assertEquals("_ec_e_", last.discovered);
    assertEquals(Set.of("a", "b", "d", "f", "g", "h"), last.misses);
    assertEquals(Status.LOSS, last.status);
    assertEquals(
        Arrays.asList(
            Part.HEAD,
            Part.BODY,
            Part.LEFT_ARM,
            Part.RIGHT_ARM,
            Part.LEFT_LEG,
            Part.RIGHT_LEG),
        last.parts);
}
 
Example 3
Source File: ObservableFromRSPublisherTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Override
protected Exception getFailure(Observable instance) {
    AtomicReference<Exception> reference = new AtomicReference<>();
    try {
        //noinspection ResultOfMethodCallIgnored
        instance.blockingLast();
    } catch (Exception e) {
        reference.set(e);
    }
    return reference.get();
}
 
Example 4
Source File: ObservableFromCompletionStageTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected String getOne(Observable instance) {
    Observable<String> single = instance.cast(String.class);
    try {
        return single.blockingLast();
    } catch (NoSuchElementException e) {
        return null;
    }
}
 
Example 5
Source File: ObservableFromCompletionStageTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Override
protected Exception getFailure(Observable instance) {
    AtomicReference<Exception> reference = new AtomicReference<>();
    try {
        //noinspection ResultOfMethodCallIgnored
        instance.blockingLast();
    } catch (Exception e) {
        reference.set(e);
    }
    return reference.get();
}
 
Example 6
Source File: HangmanTest.java    From java with MIT License 5 votes vote down vote up
@Ignore("Remove to run test")
@Test
public void firstGuess() {
    Observable<Output> result = hangman.play(
        Observable.fromArray("secret"),
        Observable.fromArray("e"));
    Output last = result.blockingLast();
    assertEquals("_e__e_", last.discovered);
    assertEquals(Collections.singleton("e"), last.guess);
    assertEquals(Collections.emptySet(), last.misses);
    assertEquals(Collections.emptyList(), last.parts);
    assertEquals(Status.PLAYING, last.status);
}
 
Example 7
Source File: HangmanTest.java    From java with MIT License 5 votes vote down vote up
@Ignore("Remove to run test")
@Test
public void firstMiss() {
    Observable<Output> result = hangman.play(
        Observable.fromArray("secret"),
        Observable.fromArray("a"));
    Output last = result.blockingLast();
    assertEquals("______", last.discovered);
    assertEquals(Collections.emptySet(), last.guess);
    assertEquals(Collections.singleton("a"), last.misses);
    assertEquals(Collections.singletonList(Part.HEAD), last.parts);
    assertEquals(Status.PLAYING, last.status);
}
 
Example 8
Source File: HangmanTest.java    From java with MIT License 5 votes vote down vote up
@Ignore("Remove to run test")
@Test
public void wonGame() {
    Observable<Output> result = hangman.play(
        Observable.fromArray("secret"),
        Observable.fromArray("a", "e", "o", "s", "c", "r", "g", "t"));
    Output last = result.blockingLast();
    assertEquals("secret", last.discovered);
    assertEquals(Set.of("c", "e", "r", "s", "t"), last.guess);
    assertEquals(Status.WIN, last.status);
}
 
Example 9
Source File: ObservableFromRSPublisherTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected String getOne(Observable instance) {
    Observable<String> single = instance.cast(String.class);
    return single.blockingLast();
}