### Question:
ChainImpl implements Interceptor.Chain { @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++; if (calls > 1) { throw new IllegalStateException("nextInterceptor " + interceptors.previous() + " must call proceed() exactly once"); } final Interceptor nextInterceptor = interceptors.next(); final ChainImpl nextChain = new ChainImpl(interceptors); return nextInterceptor.intercept(operation, nextChain); } ChainImpl(@NonNull ListIterator<Interceptor> interceptors); @NonNull static Interceptor.Chain buildChain(
            @NonNull List<Interceptor> registeredInterceptors,
            @NonNull Interceptor realInterceptor
    ); @Nullable // can be null on PreparedGetObject @Override Result proceed(@NonNull PreparedOperation<Result, WrappedResult, Data> operation);  }### Answer:
@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"); } }
@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"); } }