Search in sources :

Example 1 with SingleSubject

use of io.reactivex.rxjava3.subjects.SingleSubject in project RxJava by ReactiveX.

the class SingleTakeUntilTest method untilSingleMainError.

@Test
public void untilSingleMainError() {
    SingleSubject<Integer> main = SingleSubject.create();
    SingleSubject<Integer> other = SingleSubject.create();
    TestObserver<Integer> to = main.takeUntil(other).test();
    assertTrue("Main no observers?", main.hasObservers());
    assertTrue("Other no observers?", other.hasObservers());
    main.onError(new TestException());
    assertFalse("Main has observers?", main.hasObservers());
    assertFalse("Other has observers?", other.hasObservers());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 2 with SingleSubject

use of io.reactivex.rxjava3.subjects.SingleSubject in project RxJava by ReactiveX.

the class SingleTakeUntilTest method untilSingleOtherError.

@Test
public void untilSingleOtherError() {
    SingleSubject<Integer> main = SingleSubject.create();
    SingleSubject<Integer> other = SingleSubject.create();
    TestObserver<Integer> to = main.takeUntil(other).test();
    assertTrue("Main no observers?", main.hasObservers());
    assertTrue("Other no observers?", other.hasObservers());
    other.onError(new TestException());
    assertFalse("Main has observers?", main.hasObservers());
    assertFalse("Other has observers?", other.hasObservers());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 3 with SingleSubject

use of io.reactivex.rxjava3.subjects.SingleSubject in project RxJava by ReactiveX.

the class SingleSwitchOnNextTest method delaySwitch.

@Test
public void delaySwitch() {
    PublishProcessor<Single<Integer>> pp = PublishProcessor.create();
    TestSubscriber<Integer> ts = Single.switchOnNextDelayError(pp).test();
    assertTrue(pp.hasSubscribers());
    ts.assertEmpty();
    SingleSubject<Integer> ss1 = SingleSubject.create();
    SingleSubject<Integer> ss2 = SingleSubject.create();
    pp.onNext(ss1);
    assertTrue(ss1.hasObservers());
    pp.onNext(ss2);
    assertFalse(ss1.hasObservers());
    assertTrue(ss2.hasObservers());
    assertTrue(ss2.hasObservers());
    ss2.onError(new TestException());
    assertTrue(pp.hasSubscribers());
    ts.assertEmpty();
    pp.onComplete();
    ts.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 4 with SingleSubject

use of io.reactivex.rxjava3.subjects.SingleSubject in project RxJava by ReactiveX.

the class SingleDoOnLifecycleTest method onDisposeCrash.

@Test
public void onDisposeCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        @SuppressWarnings("unchecked") Consumer<? super Disposable> onSubscribe = mock(Consumer.class);
        Action onDispose = mock(Action.class);
        doThrow(new TestException("First")).when(onDispose).run();
        SingleSubject<Integer> ss = SingleSubject.create();
        TestObserver<Integer> to = ss.doOnLifecycle(onSubscribe, onDispose).test();
        assertTrue(ss.hasObservers());
        to.dispose();
        assertFalse(ss.hasObservers());
        TestHelper.assertUndeliverable(errors, 0, TestException.class, "First");
        verify(onSubscribe).accept(any());
        verify(onDispose).run();
    });
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 5 with SingleSubject

use of io.reactivex.rxjava3.subjects.SingleSubject in project RxJava by ReactiveX.

the class SingleTakeUntilTest method untilPublisherOtherError.

@Test
public void untilPublisherOtherError() {
    SingleSubject<Integer> main = SingleSubject.create();
    PublishProcessor<Integer> other = PublishProcessor.create();
    TestObserver<Integer> to = main.takeUntil(other).test();
    assertTrue("Main no observers?", main.hasObservers());
    assertTrue("Other no observers?", other.hasSubscribers());
    other.onError(new TestException());
    assertFalse("Main has observers?", main.hasObservers());
    assertFalse("Other has observers?", other.hasSubscribers());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 TestException (io.reactivex.rxjava3.exceptions.TestException)15 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)4