use of com.pushtorefresh.storio3.Interceptor.Chain 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);
}
use of com.pushtorefresh.storio3.Interceptor.Chain in project storio by pushtorefresh.
the class ChainImplTest method buildChain_shouldThrowIfRealInterceptorNull.
@Test
public void buildChain_shouldThrowIfRealInterceptorNull() {
try {
final List<Interceptor> interceptors = Collections.singletonList(mock(Interceptor.class));
// noinspection ConstantConditions
final Chain chain = ChainImpl.buildChain(interceptors, null);
chain.proceed(mock(PreparedOperation.class));
failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("Interceptor should not be null");
}
}
use of com.pushtorefresh.storio3.Interceptor.Chain 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.Interceptor.Chain 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.Interceptor.Chain in project storio by pushtorefresh.
the class ChainImplTest method proceed_shouldThrowIfIteratorEmpty.
@Test
public void proceed_shouldThrowIfIteratorEmpty() {
try {
final List<Interceptor> empty = Collections.emptyList();
final Chain chain = new ChainImpl(empty.listIterator());
chain.proceed(mock(PreparedOperation.class));
failBecauseExceptionWasNotThrown(IllegalStateException.class);
} catch (IllegalStateException e) {
assertThat(e).hasMessage("proceed was called on empty iterator");
}
}
Aggregations