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