Search in sources :

Example 46 with Disposable

use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.

the class ObservableForEachTest method dispose.

@Test
public void dispose() {
    PublishSubject<Integer> ps = PublishSubject.create();
    Disposable d = ps.forEachWhile(Functions.alwaysTrue());
    assertFalse(d.isDisposed());
    d.dispose();
    assertTrue(d.isDisposed());
}
Also used : Disposable(io.reactivex.disposables.Disposable) Test(org.junit.Test)

Example 47 with Disposable

use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.

the class ObservableTakeUntilTest method testTakeUntilSourceCompleted.

@Test
public void testTakeUntilSourceCompleted() {
    Disposable sSource = mock(Disposable.class);
    Disposable sOther = mock(Disposable.class);
    TestObservable source = new TestObservable(sSource);
    TestObservable other = new TestObservable(sOther);
    Observer<String> result = TestHelper.mockObserver();
    Observable<String> stringObservable = Observable.unsafeCreate(source).takeUntil(Observable.unsafeCreate(other));
    stringObservable.subscribe(result);
    source.sendOnNext("one");
    source.sendOnNext("two");
    source.sendOnCompleted();
    verify(result, times(1)).onNext("one");
    verify(result, times(1)).onNext("two");
    verify(sSource, times(1)).dispose();
    verify(sOther, times(1)).dispose();
}
Also used : Disposable(io.reactivex.disposables.Disposable) Test(org.junit.Test)

Example 48 with Disposable

use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.

the class ObservableTakeUntilTest method testTakeUntilSourceError.

@Test
public void testTakeUntilSourceError() {
    Disposable sSource = mock(Disposable.class);
    Disposable sOther = mock(Disposable.class);
    TestObservable source = new TestObservable(sSource);
    TestObservable other = new TestObservable(sOther);
    Throwable error = new Throwable();
    Observer<String> result = TestHelper.mockObserver();
    Observable<String> stringObservable = Observable.unsafeCreate(source).takeUntil(Observable.unsafeCreate(other));
    stringObservable.subscribe(result);
    source.sendOnNext("one");
    source.sendOnNext("two");
    source.sendOnError(error);
    source.sendOnNext("three");
    verify(result, times(1)).onNext("one");
    verify(result, times(1)).onNext("two");
    verify(result, times(0)).onNext("three");
    verify(result, times(1)).onError(error);
    verify(sSource, times(1)).dispose();
    verify(sOther, times(1)).dispose();
}
Also used : Disposable(io.reactivex.disposables.Disposable) Test(org.junit.Test)

Example 49 with Disposable

use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.

the class ObservableTakeUntilTest method testTakeUntilOtherCompleted.

/**
     * If the 'other' onCompletes then we unsubscribe from the source and onComplete.
     */
@Test
public void testTakeUntilOtherCompleted() {
    Disposable sSource = mock(Disposable.class);
    Disposable sOther = mock(Disposable.class);
    TestObservable source = new TestObservable(sSource);
    TestObservable other = new TestObservable(sOther);
    Observer<String> result = TestHelper.mockObserver();
    Observable<String> stringObservable = Observable.unsafeCreate(source).takeUntil(Observable.unsafeCreate(other));
    stringObservable.subscribe(result);
    source.sendOnNext("one");
    source.sendOnNext("two");
    other.sendOnCompleted();
    source.sendOnNext("three");
    verify(result, times(1)).onNext("one");
    verify(result, times(1)).onNext("two");
    verify(result, times(0)).onNext("three");
    verify(result, times(1)).onComplete();
    verify(sSource, times(1)).dispose();
    // unsubscribed since SafeSubscriber unsubscribes after onComplete
    verify(sOther, times(1)).dispose();
}
Also used : Disposable(io.reactivex.disposables.Disposable) Test(org.junit.Test)

Example 50 with Disposable

use of io.reactivex.disposables.Disposable in project RxJava by ReactiveX.

the class AsyncSubscriptionTest method testReplaceResource2.

@Test
public void testReplaceResource2() {
    AsyncSubscription as = new AsyncSubscription();
    Disposable r = mock(Disposable.class);
    assertTrue(as.replaceResource(r));
    Disposable r2 = mock(Disposable.class);
    as.replaceResource(r2);
    as.cancel();
    verify(r, never()).dispose();
    verify(r2).dispose();
}
Also used : Disposable(io.reactivex.disposables.Disposable) Test(org.junit.Test)

Aggregations

Disposable (io.reactivex.disposables.Disposable)224 Test (org.junit.Test)95 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)31 Logger (chat.rocket.android.helper.Logger)19 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 Worker (io.reactivex.Scheduler.Worker)15 List (java.util.List)14 Single (io.reactivex.Single)13 Function (io.reactivex.functions.Function)13 NonNull (io.reactivex.annotations.NonNull)12 Nullable (android.support.annotation.Nullable)11 Bundle (android.os.Bundle)10 CountingRunnable (io.reactivex.android.testutil.CountingRunnable)10 EmptyDisposable (io.reactivex.internal.disposables.EmptyDisposable)10 TestSubscriber (io.reactivex.subscribers.TestSubscriber)10 Optional (com.fernandocejas.arrow.optional.Optional)9 Schedulers (io.reactivex.schedulers.Schedulers)9 TimeUnit (java.util.concurrent.TimeUnit)8 NonNull (android.support.annotation.NonNull)7