Search in sources :

Example 1 with SimpleCancelable

use of com.amplifyframework.testutils.SimpleCancelable in project amplify-android by aws-amplify.

the class RxAdaptersTest method underlyingOperationIsCanceledWhenSingleSubscriptionIsDisposed.

/**
 * {@link CancelableBehaviors#toSingle(CancelableBehaviors.ResultEmitter)}
 * returns a {@link Single} which can be canceled. The Amplify {@link Cancelable}
 * returned by that emitter will also show as canceled.
 */
@Test
public void underlyingOperationIsCanceledWhenSingleSubscriptionIsDisposed() {
    SimpleCancelable cancelable = new SimpleCancelable();
    TestObserver<?> observer = CancelableBehaviors.toSingle(((onResult, onError) -> cancelable)).test();
    observer.dispose();
    assertTrue(observer.isDisposed());
    assertTrue(cancelable.isCanceled());
}
Also used : SimpleCancelable(com.amplifyframework.testutils.SimpleCancelable) Test(org.junit.Test)

Example 2 with SimpleCancelable

use of com.amplifyframework.testutils.SimpleCancelable in project amplify-android by aws-amplify.

the class RxAdaptersTest method underlyingCancelIsCalledWhenObservableSubscriptionIsDisposed.

/**
 * The {@link Observable} returned by
 * {@link CancelableBehaviors#toObservable(CancelableBehaviors.StreamEmitter)}
 * is cancelable.
 */
@Test
public void underlyingCancelIsCalledWhenObservableSubscriptionIsDisposed() {
    SimpleCancelable cancelable = new SimpleCancelable();
    TestObserver<?> observer = CancelableBehaviors.toObservable((onStart, onItem, onError, onComplete) -> cancelable).test();
    observer.dispose();
    assertTrue(observer.isDisposed());
    assertTrue(cancelable.isCanceled());
}
Also used : Single(io.reactivex.rxjava3.core.Single) SimpleCancelable(com.amplifyframework.testutils.SimpleCancelable) CancelableBehaviors(com.amplifyframework.rx.RxAdapters.CancelableBehaviors) VoidBehaviors(com.amplifyframework.rx.RxAdapters.VoidBehaviors) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Completable(io.reactivex.rxjava3.core.Completable) Sleep(com.amplifyframework.testutils.Sleep) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Cancelable(com.amplifyframework.core.async.Cancelable) Observable(io.reactivex.rxjava3.core.Observable) RandomString(com.amplifyframework.testutils.random.RandomString) NoOpCancelable(com.amplifyframework.core.async.NoOpCancelable) Disposable(io.reactivex.rxjava3.disposables.Disposable) UndeliverableException(io.reactivex.rxjava3.exceptions.UndeliverableException) SimpleCancelable(com.amplifyframework.testutils.SimpleCancelable) Test(org.junit.Test)

Aggregations

SimpleCancelable (com.amplifyframework.testutils.SimpleCancelable)2 Test (org.junit.Test)2 Cancelable (com.amplifyframework.core.async.Cancelable)1 NoOpCancelable (com.amplifyframework.core.async.NoOpCancelable)1 CancelableBehaviors (com.amplifyframework.rx.RxAdapters.CancelableBehaviors)1 VoidBehaviors (com.amplifyframework.rx.RxAdapters.VoidBehaviors)1 Sleep (com.amplifyframework.testutils.Sleep)1 RandomString (com.amplifyframework.testutils.random.RandomString)1 Completable (io.reactivex.rxjava3.core.Completable)1 Observable (io.reactivex.rxjava3.core.Observable)1 Single (io.reactivex.rxjava3.core.Single)1 Disposable (io.reactivex.rxjava3.disposables.Disposable)1 UndeliverableException (io.reactivex.rxjava3.exceptions.UndeliverableException)1 TestObserver (io.reactivex.rxjava3.observers.TestObserver)1 Assert.assertTrue (org.junit.Assert.assertTrue)1