Search in sources :

Example 6 with PreparedOperation

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

the class LoggingInterceptorTest method interceptShouldLogToLogger.

@Test
public void interceptShouldLogToLogger() {
    final String result = "some result";
    final String data = "some data";
    final Interceptor.Chain chain = new TestChain(result);
    final PreparedOperation operation = new TestOperation(data);
    loggingInterceptor.intercept(operation, chain);
    // TODO how to test timings?
    assertThat(resultBuilder.toString()).startsWith("TestOperation\n=> data: some data\n<= result: some result\ntook ");
}
Also used : PreparedOperation(com.pushtorefresh.storio3.operations.PreparedOperation) Test(org.junit.Test)

Example 7 with PreparedOperation

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

the class LoggingInterceptorTest method defaultLoggerShouldLogToAndroidLog.

@Config(shadows = { ShadowLog.class })
@Test
public void defaultLoggerShouldLogToAndroidLog() {
    loggingInterceptor = LoggingInterceptor.defaultLogger();
    final String result = "some result";
    final String data = "some data";
    final Interceptor.Chain chain = new TestChain(result);
    final PreparedOperation operation = new TestOperation(data);
    loggingInterceptor.intercept(operation, chain);
    // TODO how to test timings?
    assertThat(androidLogBuilder.toString()).startsWith("StorIO:TestOperation\n=> data: some data\n<= result: some result\ntook ");
}
Also used : PreparedOperation(com.pushtorefresh.storio3.operations.PreparedOperation) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 8 with PreparedOperation

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

the class CompletableOnSubscribeExecuteAsBlockingTest method shouldCallOnErrorIfExceptionOccurred.

@SuppressWarnings({ "ThrowableInstanceNeverThrown", "ResourceType" })
@Test
public void shouldCallOnErrorIfExceptionOccurred() {
    final PreparedCompletableOperation preparedOperation = mock(PreparedCompletableOperation.class);
    StorIOException expectedException = new StorIOException("test exception");
    when(preparedOperation.executeAsBlocking()).thenThrow(expectedException);
    TestObserver testObserver = new TestObserver();
    Completable completable = Completable.create(new CompletableOnSubscribeExecuteAsBlocking(preparedOperation));
    verifyZeroInteractions(preparedOperation);
    completable.subscribe(testObserver);
    testObserver.assertError(expectedException);
    testObserver.assertNotComplete();
    verify(preparedOperation).executeAsBlocking();
    verify(preparedOperation, never()).asRxFlowable(any(BackpressureStrategy.class));
    verify(preparedOperation, never()).asRxSingle();
    verify(preparedOperation, never()).asRxCompletable();
}
Also used : Completable(io.reactivex.Completable) StorIOException(com.pushtorefresh.storio3.StorIOException) PreparedCompletableOperation(com.pushtorefresh.storio3.operations.PreparedCompletableOperation) BackpressureStrategy(io.reactivex.BackpressureStrategy) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 9 with PreparedOperation

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

the class SingleOnSubscribeExecuteAsBlockingTest method shouldCallOnErrorIfExceptionOccurred.

@SuppressWarnings("CheckResult")
@Test
public void shouldCallOnErrorIfExceptionOccurred() {
    // noinspection unchecked
    final PreparedOperation<Object, Object, Object> preparedOperation = mock(PreparedOperation.class);
    StorIOException expectedException = new StorIOException("test exception");
    when(preparedOperation.executeAsBlocking()).thenThrow(expectedException);
    TestObserver<Object> testObserver = new TestObserver<Object>();
    Single<Object> single = Single.create(new SingleOnSubscribeExecuteAsBlocking<Object, Object, Object>(preparedOperation));
    verifyZeroInteractions(preparedOperation);
    single.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 10 with PreparedOperation

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

the class ChainImplTest method proceed_shouldThrowIfCalledMultipleTimes.

@Test
public void proceed_shouldThrowIfCalledMultipleTimes() {
    final List<Interceptor> interceptors = Arrays.asList(mock(Interceptor.class), mock(Interceptor.class));
    try {
        final Chain chain = new ChainImpl(interceptors.listIterator());
        final PreparedOperation operation = mock(PreparedOperation.class);
        chain.proceed(operation);
        chain.proceed(operation);
        failBecauseExceptionWasNotThrown(IllegalStateException.class);
    } catch (IllegalStateException e) {
        assertThat(e).hasMessage("nextInterceptor " + interceptors.get(0) + " must call proceed() exactly once");
    }
}
Also used : Chain(com.pushtorefresh.storio3.Interceptor.Chain) PreparedOperation(com.pushtorefresh.storio3.operations.PreparedOperation) Interceptor(com.pushtorefresh.storio3.Interceptor) Test(org.junit.Test)

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