Java Code Examples for io.reactivex.observers.TestObserver#assertEmpty()

The following examples show how to use io.reactivex.observers.TestObserver#assertEmpty() . 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: RxTiPresenterUtilsTest.java    From ThirtyInch with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeliverLatestToView_Empty() throws Exception {
    mPresenter.create();

    TestObserver<Integer> testObserver = new TestObserver<>();
    Observable.<Integer>empty()
            .compose(RxTiPresenterUtils.<Integer>deliverLatestToView(mPresenter))
            .subscribe(testObserver);

    mPresenter.attachView(mView);

    testObserver.assertNotComplete();
    testObserver.assertNoErrors();
    testObserver.assertEmpty();
}
 
Example 2
Source File: RxTiPresenterUtilsTest.java    From ThirtyInch with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeliverLatestToView_ViewNeverReady() throws Exception {
    mPresenter.create();

    TestObserver<Integer> testObserver = new TestObserver<>();
    Observable.just(1, 2, 3)
            .compose(RxTiPresenterUtils.<Integer>deliverLatestToView(mPresenter))
            .subscribe(testObserver);

    testObserver.assertNotComplete();
    testObserver.assertNoErrors();
    testObserver.assertEmpty();
}
 
Example 3
Source File: BehaviorWithLatestTest.java    From akarnokd-misc with Apache License 2.0 5 votes vote down vote up
@Test
public void secondInit() {
    BehaviorSubject<String> s1 = BehaviorSubject.create();
    BehaviorSubject<String> s2 = BehaviorSubject.createDefault("");

    TestObserver<Boolean> to = s1.withLatestFrom(s2, (a, b) -> true)
    .test();

    to.assertEmpty();

    s1.onNext("");

    to.assertValue(true);
}
 
Example 4
Source File: RxRelayIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenObserverSubscribedToBehaviorRelayWithoutDefaultValue_thenItIsEmpty() {
    BehaviorRelay<Integer> behaviorRelay = BehaviorRelay.create();
    TestObserver<Integer> firstObserver = new TestObserver<>();
    behaviorRelay.subscribe(firstObserver);
    firstObserver.assertEmpty();
}
 
Example 5
Source File: RxRelayIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenObserverSubscribedToReplayRelayWithMaxAge_thenItReceivesEmittedEvents () throws InterruptedException {
    ReplayRelay<Integer> replayRelay = ReplayRelay.createWithTime(2000, TimeUnit.MILLISECONDS, new SingleScheduler());
    TestObserver<Integer> firstObserver = TestObserver.create();
    replayRelay.accept(5);
    replayRelay.accept(10);
    replayRelay.accept(15);
    replayRelay.accept(20);
    Thread.sleep(3000);
    replayRelay.subscribe(firstObserver);
    firstObserver.assertEmpty();
}
 
Example 6
Source File: RxRelayIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenTwoObserversSubscribedToRandomRelay_thenOnlyOneReceivesEvent () {
    RandomRelay randomRelay = new RandomRelay();
    TestObserver<Integer> firstObserver = TestObserver.create();
    TestObserver<Integer> secondObserver = TestObserver.create();
    randomRelay.subscribe(firstObserver);
    randomRelay.subscribe(secondObserver);
    randomRelay.accept(5);
    if(firstObserver.values().isEmpty()) {
        secondObserver.assertValue(5);
    } else {
        firstObserver.assertValue(5);
        secondObserver.assertEmpty();
    }
}
 
Example 7
Source File: BehaviorWithLatestTest.java    From akarnokd-misc with Apache License 2.0 4 votes vote down vote up
@Test
public void firstInit() {
    BehaviorSubject<String> s1 = BehaviorSubject.createDefault("");
    BehaviorSubject<String> s2 = BehaviorSubject.create();

    TestObserver<Boolean> to = s1.withLatestFrom(s2, (a, b) -> true)
    .test();

    to.assertEmpty();

    s2.onNext("");

    to.assertEmpty();

    s1.onNext("");

    to.assertValue(true);
}