Java Code Examples for rx.observers.TestSubscriber#assertNoTerminalEvent()

The following examples show how to use rx.observers.TestSubscriber#assertNoTerminalEvent() . 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: RxStoresTest.java    From grox with Apache License 2.0 6 votes vote down vote up
@Test
public void states_should_stopObservingStateChanges() {
  //GIVEN
  Store<Integer> store = new Store<>(0);
  TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
  final Subscription subscription = states(store).subscribe(testSubscriber);

  //WHEN
  subscription.unsubscribe();
  store.dispatch(integer -> integer + 1);
  final Integer state = store.getState();

  //THEN
  testSubscriber.assertNoTerminalEvent();
  testSubscriber.assertValue(0);
  testSubscriber.assertUnsubscribed();
  assertThat(state, is(1));
}
 
Example 2
Source File: RecordIOOperatorTest.java    From mesos-rxjava with Apache License 2.0 6 votes vote down vote up
@NotNull
static List<Event> runTestOnChunks(@NotNull final List<ByteBuf> chunks) {
    final TestSubscriber<byte[]> child = new TestSubscriber<>();
    final Subscriber<ByteBuf> call = new RecordIOOperator().call(child);

    assertThat(call).isInstanceOf(RecordIOOperator.RecordIOSubscriber.class);

    final RecordIOOperator.RecordIOSubscriber subscriber = (RecordIOOperator.RecordIOSubscriber) call;
    chunks.stream().forEach(subscriber::onNext);
    child.assertNoErrors();
    child.assertNotCompleted();
    child.assertNoTerminalEvent();
    assertThat(subscriber.messageSizeBytesBuffer).isEmpty();
    assertThat(subscriber.messageBytes).isNull();
    assertThat(subscriber.remainingBytesForMessage).isEqualTo(0);

    return CollectionUtils.listMap(child.getOnNextEvents(), (bs) -> {
        try {
            return Event.parseFrom(bs);
        } catch (InvalidProtocolBufferException e) {
            throw new RuntimeException(e);
        }
    });
}
 
Example 3
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 4
Source File: ObservableQueueTest.java    From Jockey with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubscribeTwice() {
    TestSubscriber<String> subscriber1 = new TestSubscriber<>();
    TestSubscriber<String> subscriber2 = new TestSubscriber<>();

    mSubject.toObservable().subscribe(subscriber1);
    mSubject.enqueue("sub-1 obj-1");
    mSubject.enqueue("sub-1 obj-2");

    subscriber1.assertNoTerminalEvent();
    subscriber1.assertValues("sub-1 obj-1", "sub-1 obj-2");

    mSubject.toObservable().subscribe(subscriber2);
    subscriber1.assertCompleted();

    mSubject.enqueue("sub-2 obj-1");
    mSubject.enqueue("sub-2 obj-2");

    subscriber2.assertNoTerminalEvent();
    subscriber2.assertValues("sub-2 obj-1", "sub-2 obj-2");
}
 
Example 5
Source File: ObservableQueueTest.java    From Jockey with Apache License 2.0 6 votes vote down vote up
@Test
public void testEarlyUnsubscribeDoesNotDestroyQueue() {
    TestSubscriber<String> subscriber1 = new TestSubscriber<>();
    TestSubscriber<String> subscriber2 = new TestSubscriber<>();

    mSubject.enqueue("Thing 1");
    mSubject.enqueue("Thing 2");
    mSubject.enqueue("Thing 3");
    mSubject.enqueue("Thing 4");

    mSubject.toObservable().take(1).subscribe(subscriber1);

    subscriber1.assertTerminalEvent();
    subscriber1.assertValue("Thing 1");

    mSubject.toObservable().subscribe(subscriber2);
    subscriber2.assertNoTerminalEvent();
    subscriber2.assertValues("Thing 2", "Thing 3", "Thing 4");
}
 
Example 6
Source File: RxStoresTest.java    From grox with Apache License 2.0 5 votes vote down vote up
@Test
public void states_should_observeInitialState() {
  //GIVEN
  Store<Integer> store = new Store<>(0);
  TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();

  //WHEN
  states(store).subscribe(testSubscriber);

  //THEN
  testSubscriber.assertNoTerminalEvent();
  testSubscriber.assertValue(0);
}
 
Example 7
Source File: RxStoresTest.java    From grox with Apache License 2.0 5 votes vote down vote up
@Test
public void states_should_observeStateChanges() {
  //GIVEN
  Store<Integer> store = new Store<>(0);
  TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
  states(store).subscribe(testSubscriber);

  //WHEN
  store.dispatch(integer -> integer + 1);

  //THEN
  testSubscriber.assertNoTerminalEvent();
  testSubscriber.assertValues(0, 1);
}
 
Example 8
Source File: RxAppStateMonitorTest.java    From RxAppState with MIT License 5 votes vote down vote up
@Test
public void emitsAppStates() {
    FakeApplication fakeApplication = new FakeApplication();
    TestSubscriber<AppState> subscriber = TestSubscriber.create();
    RxAppStateMonitor.monitor(fakeApplication).subscribe(subscriber);

    fakeApplication.goForeground();
    fakeApplication.goBackground();

    subscriber.assertValues(FOREGROUND, BACKGROUND);
    subscriber.assertNoTerminalEvent();
}
 
Example 9
Source File: ObservableQueueTest.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Test
public void testEnqueueOnce() {
    TestSubscriber<String> subscriber = new TestSubscriber<>();

    mSubject.toObservable().subscribe(subscriber);
    subscriber.assertNoTerminalEvent();
    subscriber.assertNoValues();

    mSubject.enqueue("Hello world!");
    subscriber.assertNoTerminalEvent();
    subscriber.assertValue("Hello world!");
}
 
Example 10
Source File: ObservableQueueTest.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Test
public void testEnqueueSeveralTimes() {
    TestSubscriber<String> subscriber = new TestSubscriber<>();

    mSubject.toObservable().subscribe(subscriber);
    subscriber.assertNoTerminalEvent();
    subscriber.assertNoValues();

    mSubject.enqueue("Hello world!");
    mSubject.enqueue("My hands are typing words!");
    mSubject.enqueue("HAAAAAANDS!");
    subscriber.assertNoTerminalEvent();
    subscriber.assertValues("Hello world!", "My hands are typing words!", "HAAAAAANDS!");
}
 
Example 11
Source File: ObservableQueueTest.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Test
public void testValuesPostedAfterLateSubscribe() {
    TestSubscriber<String> subscriber = new TestSubscriber<>();

    mSubject.enqueue("Hello world!");
    mSubject.enqueue("My hands are typing words!");
    mSubject.enqueue("HAAAAAANDS!");

    mSubject.toObservable().subscribe(subscriber);
    subscriber.assertNoTerminalEvent();
    subscriber.assertValues("Hello world!", "My hands are typing words!", "HAAAAAANDS!");
}
 
Example 12
Source File: ObservableQueueTest.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Test
public void testConsistencyOfEnqueueBeforeSubscribe() {
    TestSubscriber<String> subscriber = new TestSubscriber<>();

    mSubject.enqueue("Hello world!");
    mSubject.enqueue("My hands are typing words!");

    Observable<String> observable = mSubject.toObservable();

    mSubject.enqueue("HAAAAAANDS!");
    observable.subscribe(subscriber);

    subscriber.assertNoTerminalEvent();
    subscriber.assertValues("Hello world!", "My hands are typing words!", "HAAAAAANDS!");
}