Java Code Examples for rx.subjects.BehaviorSubject#subscribe()

The following examples show how to use rx.subjects.BehaviorSubject#subscribe() . 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: AwaitableEventSubscriberDecoratorTest.java    From mesos-rxjava with Apache License 2.0 6 votes vote down vote up
@Test
public void awaitEventWorks_onNext() throws Exception {
    final TestSubscriber<String> testSubscriber = new TestSubscriber<>();
    final AwaitableEventSubscriberDecorator<String> sub = new AwaitableEventSubscriberDecorator<>(testSubscriber);

    final BehaviorSubject<String> subject = BehaviorSubject.create();

    final Subscription subscription = subject.subscribe(sub);

    async.run(() -> subject.onNext("hello"));

    sub.awaitEvent();
    testSubscriber.assertValue("hello");
    testSubscriber.assertNoTerminalEvent();
    subscription.unsubscribe();
}
 
Example 2
Source File: AwaitableEventSubscriberDecoratorTest.java    From mesos-rxjava with Apache License 2.0 6 votes vote down vote up
@Test
public void awaitEventWorks_onError() throws Exception {
    final TestSubscriber<String> testSubscriber = new TestSubscriber<>();
    final AwaitableEventSubscriberDecorator<String> sub = new AwaitableEventSubscriberDecorator<>(testSubscriber);

    final BehaviorSubject<String> subject = BehaviorSubject.create();

    final Subscription subscription = subject.subscribe(sub);

    final RuntimeException e = new RuntimeException("doesn't matter");
    async.run(() -> subject.onError(e));

    sub.awaitEvent();
    testSubscriber.assertNoValues();
    testSubscriber.assertError(e);
    subscription.unsubscribe();
}
 
Example 3
Source File: AwaitableEventSubscriberDecoratorTest.java    From mesos-rxjava with Apache License 2.0 6 votes vote down vote up
@Test
public void awaitEventWorks_onCompleted() throws Exception {
    final TestSubscriber<String> testSubscriber = new TestSubscriber<>();
    final AwaitableEventSubscriberDecorator<String> sub = new AwaitableEventSubscriberDecorator<>(testSubscriber);

    final BehaviorSubject<String> subject = BehaviorSubject.create();

    final Subscription subscription = subject.subscribe(sub);

    async.run(subject::onCompleted);

    sub.awaitEvent();
    testSubscriber.assertNoValues();
    testSubscriber.assertCompleted();
    subscription.unsubscribe();
}
 
Example 4
Source File: AwaitableEventSubscriberDecoratorTest.java    From mesos-rxjava with Apache License 2.0 6 votes vote down vote up
@Test
public void awaitEventWorks() throws Exception {
    final TestSubscriber<String> testSubscriber = new TestSubscriber<>();
    final AwaitableEventSubscriberDecorator<String> sub = new AwaitableEventSubscriberDecorator<>(testSubscriber);

    final BehaviorSubject<String> subject = BehaviorSubject.create();

    final Subscription subscription = subject.subscribe(sub);

    async.run(() -> {
        subject.onNext("hello");
        subject.onNext("world");
        subject.onNext("!");
        subject.onCompleted();
    });

    sub.awaitEvent(Integer.MAX_VALUE);
    testSubscriber.assertValues("hello", "world", "!");
    testSubscriber.assertCompleted();
    testSubscriber.assertNoErrors();
    subscription.unsubscribe();
}