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());
}
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();
}
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();
}
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();
}
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();
}
Aggregations