Search in sources :

Example 6 with PublishSubject

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

the class SingleSubscribeTest method biConsumerDispose.

@Test
public void biConsumerDispose() {
    PublishSubject<Integer> ps = PublishSubject.create();
    Disposable d = ps.single(-99).subscribe(new BiConsumer<Object, Object>() {

        @Override
        public void accept(Object t1, Object t2) throws Exception {
        }
    });
    assertFalse(d.isDisposed());
    d.dispose();
    assertTrue(d.isDisposed());
    assertFalse(ps.hasObservers());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with PublishSubject

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

the class SingleCacheTest method crossCancelOnError.

@Test
public void crossCancelOnError() {
    PublishSubject<Integer> ps = PublishSubject.create();
    Single<Integer> cache = ps.single(-99).cache();
    final TestSubscriber<Integer> ts1 = new TestSubscriber<>();
    TestSubscriber<Integer> ts2 = new TestSubscriber<Integer>() {

        @Override
        public void onError(Throwable t) {
            super.onError(t);
            ts1.cancel();
        }
    };
    cache.toFlowable().subscribe(ts2);
    cache.toFlowable().subscribe(ts1);
    ps.onError(new TestException());
    ts1.assertNoValues().assertNoErrors().assertNotComplete();
    ts2.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) Test(org.junit.Test)

Example 8 with PublishSubject

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

the class PublishSubjectTest method currentStateMethodsError.

@Test
public void currentStateMethodsError() {
    PublishSubject<Object> as = PublishSubject.create();
    assertFalse(as.hasThrowable());
    assertFalse(as.hasComplete());
    assertNull(as.getThrowable());
    as.onError(new TestException());
    assertTrue(as.hasThrowable());
    assertFalse(as.hasComplete());
    assertTrue(as.getThrowable() instanceof TestException);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 9 with PublishSubject

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

the class ObservableDelaySubscriptionOtherTest method noPrematureSubscription.

@Test
public void noPrematureSubscription() {
    PublishSubject<Object> other = PublishSubject.create();
    TestObserver<Integer> to = new TestObserver<>();
    final AtomicInteger subscribed = new AtomicInteger();
    Observable.just(1).doOnSubscribe(new Consumer<Disposable>() {

        @Override
        public void accept(Disposable d) {
            subscribed.getAndIncrement();
        }
    }).delaySubscription(other).subscribe(to);
    to.assertNotComplete();
    to.assertNoErrors();
    to.assertNoValues();
    Assert.assertEquals("Premature subscription", 0, subscribed.get());
    other.onNext(1);
    Assert.assertEquals("No subscription", 1, subscribed.get());
    to.assertValue(1);
    to.assertNoErrors();
    to.assertComplete();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Disposable(io.reactivex.rxjava3.disposables.Disposable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.rxjava3.observers.TestObserver)

Example 10 with PublishSubject

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

the class ObservableDelaySubscriptionOtherTest method noPrematureSubscriptionToError.

@Test
public void noPrematureSubscriptionToError() {
    PublishSubject<Object> other = PublishSubject.create();
    TestObserver<Integer> to = new TestObserver<>();
    final AtomicInteger subscribed = new AtomicInteger();
    Observable.<Integer>error(new TestException()).doOnSubscribe(new Consumer<Disposable>() {

        @Override
        public void accept(Disposable d) {
            subscribed.getAndIncrement();
        }
    }).delaySubscription(other).subscribe(to);
    to.assertNotComplete();
    to.assertNoErrors();
    to.assertNoValues();
    Assert.assertEquals("Premature subscription", 0, subscribed.get());
    other.onComplete();
    Assert.assertEquals("No subscription", 1, subscribed.get());
    to.assertNoValues();
    to.assertNotComplete();
    to.assertError(TestException.class);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.rxjava3.observers.TestObserver)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)69 Test (org.junit.Test)68 InOrder (org.mockito.InOrder)36 Observable (io.reactivex.rxjava3.core.Observable)28 Disposable (io.reactivex.rxjava3.disposables.Disposable)17 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)17 TestObserver (io.reactivex.rxjava3.observers.TestObserver)14 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 ObservableReplay (io.reactivex.rxjava3.internal.operators.observable.ObservableReplay)4 IOException (java.io.IOException)4 TargetApi (android.annotation.TargetApi)3 Function (io.reactivex.rxjava3.functions.Function)3 CrashingIterable (io.reactivex.rxjava3.internal.util.CrashingIterable)3 PublishSubject (io.reactivex.rxjava3.subjects.PublishSubject)3 Matchers.anyString (org.mockito.Matchers.anyString)3 NonNull (io.reactivex.rxjava3.annotations.NonNull)2 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)1 Observer (io.reactivex.rxjava3.core.Observer)1 GroupedObservable (io.reactivex.rxjava3.observables.GroupedObservable)1