Search in sources :

Example 1 with PreparedOperation

use of com.pushtorefresh.storio3.operations.PreparedOperation in project storio by pushtorefresh.

the class SingleOnSubscribeExecuteAsBlockingOptionalTest method shouldCallOnErrorIfExceptionOccurred.

@SuppressWarnings("CheckResult")
@Test
public void shouldCallOnErrorIfExceptionOccurred() {
    // noinspection unchecked
    final PreparedOperation<Object, Optional<Object>, Object> preparedOperation = mock(PreparedOperation.class);
    StorIOException expectedException = new StorIOException("test exception");
    when(preparedOperation.executeAsBlocking()).thenThrow(expectedException);
    TestObserver<Optional<Object>> testObserver = new TestObserver<Optional<Object>>();
    Single<Optional<Object>> single = Single.create(new SingleOnSubscribeExecuteAsBlockingOptional<Object, Object>(preparedOperation));
    verifyZeroInteractions(preparedOperation);
    single.subscribe(testObserver);
    testObserver.assertError(expectedException);
    testObserver.assertNotComplete();
    verify(preparedOperation).executeAsBlocking();
}
Also used : Optional(com.pushtorefresh.storio3.Optional) StorIOException(com.pushtorefresh.storio3.StorIOException) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 2 with PreparedOperation

use of com.pushtorefresh.storio3.operations.PreparedOperation in project storio by pushtorefresh.

the class CompletableOnSubscribeExecuteAsBlockingTest method shouldExecuteAsBlockingAfterSubscription.

@SuppressWarnings("ResourceType")
@Test
public void shouldExecuteAsBlockingAfterSubscription() {
    final PreparedCompletableOperation preparedOperation = mock(PreparedCompletableOperation.class);
    TestObserver testObserver = new TestObserver();
    verifyZeroInteractions(preparedOperation);
    Completable completable = Completable.create(new CompletableOnSubscribeExecuteAsBlocking(preparedOperation));
    verifyZeroInteractions(preparedOperation);
    completable.subscribe(testObserver);
    testObserver.assertNoErrors();
    testObserver.assertComplete();
    verify(preparedOperation).executeAsBlocking();
    verify(preparedOperation, never()).asRxFlowable(any(BackpressureStrategy.class));
    verify(preparedOperation, never()).asRxSingle();
    verify(preparedOperation, never()).asRxCompletable();
}
Also used : Completable(io.reactivex.Completable) PreparedCompletableOperation(com.pushtorefresh.storio3.operations.PreparedCompletableOperation) BackpressureStrategy(io.reactivex.BackpressureStrategy) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 3 with PreparedOperation

use of com.pushtorefresh.storio3.operations.PreparedOperation in project storio by pushtorefresh.

the class MaybeOnSubscribeExecuteAsBlockingTest method shouldCallOnErrorIfExceptionOccurred.

@SuppressWarnings("CheckResult")
@Test
public void shouldCallOnErrorIfExceptionOccurred() {
    // noinspection unchecked
    final PreparedMaybeOperation<Object, Object, Object> preparedOperation = mock(PreparedMaybeOperation.class);
    StorIOException expectedException = new StorIOException("test exception");
    when(preparedOperation.executeAsBlocking()).thenThrow(expectedException);
    TestObserver<Object> testObserver = new TestObserver<Object>();
    Maybe<Object> maybe = Maybe.create(new MaybeOnSubscribeExecuteAsBlocking<Object, Object, Object>(preparedOperation));
    verifyZeroInteractions(preparedOperation);
    maybe.subscribe(testObserver);
    testObserver.assertError(expectedException);
    testObserver.assertNotComplete();
    verify(preparedOperation).executeAsBlocking();
}
Also used : StorIOException(com.pushtorefresh.storio3.StorIOException) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 4 with PreparedOperation

use of com.pushtorefresh.storio3.operations.PreparedOperation in project storio by pushtorefresh.

the class ChainImpl method proceed.

// can be null on PreparedGetObject
@Nullable
@Override
public <Result, WrappedResult, Data> Result proceed(@NonNull PreparedOperation<Result, WrappedResult, Data> operation) {
    if (!interceptors.hasNext()) {
        throw new IllegalStateException("proceed was called on empty iterator");
    }
    calls++;
    // Confirm that this is the only call to chain.proceed().
    if (calls > 1) {
        throw new IllegalStateException("nextInterceptor " + interceptors.previous() + " must call proceed() exactly once");
    }
    // Call the nextChain nextInterceptor in the chain.
    final Interceptor nextInterceptor = interceptors.next();
    final ChainImpl nextChain = new ChainImpl(interceptors);
    return nextInterceptor.intercept(operation, nextChain);
}
Also used : Interceptor(com.pushtorefresh.storio3.Interceptor) Nullable(android.support.annotation.Nullable)

Example 5 with PreparedOperation

use of com.pushtorefresh.storio3.operations.PreparedOperation in project storio by pushtorefresh.

the class SchedulerChecker method check.

private void check(@NonNull PreparedOperation operation) {
    final PreparedOperation operationSpy = spy(operation);
    verify(storIOSQLite).defaultRxScheduler();
    operationSpy.asRxFlowable(MISSING).subscribe();
    verify(operationSpy, never()).executeAsBlocking();
    scheduler.triggerActions();
    verify(operationSpy).executeAsBlocking();
}
Also used : PreparedOperation(com.pushtorefresh.storio3.operations.PreparedOperation)

Aggregations

Test (org.junit.Test)9 PreparedOperation (com.pushtorefresh.storio3.operations.PreparedOperation)5 TestObserver (io.reactivex.observers.TestObserver)5 StorIOException (com.pushtorefresh.storio3.StorIOException)4 Interceptor (com.pushtorefresh.storio3.Interceptor)3 Chain (com.pushtorefresh.storio3.Interceptor.Chain)2 PreparedCompletableOperation (com.pushtorefresh.storio3.operations.PreparedCompletableOperation)2 BackpressureStrategy (io.reactivex.BackpressureStrategy)2 Completable (io.reactivex.Completable)2 Nullable (android.support.annotation.Nullable)1 Optional (com.pushtorefresh.storio3.Optional)1 InOrder (org.mockito.InOrder)1 Config (org.robolectric.annotation.Config)1