Search in sources :

Example 1 with CancelableBehaviors

use of com.amplifyframework.rx.RxAdapters.CancelableBehaviors in project amplify-android by aws-amplify.

the class RxAdaptersTest method singleFiresErrorWhenErrorEmitted.

/**
 * The {@link Single} returned by
 * {@link CancelableBehaviors#toSingle(CancelableBehaviors.ResultEmitter)}
 * will dispatch an error when the {@link CancelableBehaviors.ResultEmitter}'s error consumer is
 * invoked.
 */
@Test
public void singleFiresErrorWhenErrorEmitted() {
    Throwable expected = new Throwable(RandomString.string());
    CancelableBehaviors.toSingle((onResult, onError) -> {
        onError.accept(expected);
        return new NoOpCancelable();
    }).test().assertError(expected).assertNoValues();
}
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) NoOpCancelable(com.amplifyframework.core.async.NoOpCancelable) Test(org.junit.Test)

Example 2 with CancelableBehaviors

use of com.amplifyframework.rx.RxAdapters.CancelableBehaviors in project amplify-android by aws-amplify.

the class RxAdaptersTest method singleFiresResultWhenEmitted.

/**
 * The {@link Single} returned by
 * {@link CancelableBehaviors#toSingle(CancelableBehaviors.ResultEmitter)}
 * will dispatch a result when the {@link CancelableBehaviors.ResultEmitter}'s value consumer
 * is invoked.
 */
@Test
public void singleFiresResultWhenEmitted() {
    String result = RandomString.string();
    CancelableBehaviors.toSingle((onResult, onError) -> {
        onResult.accept(result);
        return new NoOpCancelable();
    }).test().assertValue(result).assertComplete();
}
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) RandomString(com.amplifyframework.testutils.random.RandomString) NoOpCancelable(com.amplifyframework.core.async.NoOpCancelable) Test(org.junit.Test)

Example 3 with CancelableBehaviors

use of com.amplifyframework.rx.RxAdapters.CancelableBehaviors 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

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