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