Search in sources :

Example 6 with Chain

use of com.pushtorefresh.storio3.Interceptor.Chain 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)

Example 7 with Chain

use of com.pushtorefresh.storio3.Interceptor.Chain in project storio by pushtorefresh.

the class ChainImplTest method buildChain_placesRealInterceptorAfterRegistered.

@Test
public void buildChain_placesRealInterceptorAfterRegistered() {
    Interceptor registered1 = spy(new IntermediateInterceptor());
    Interceptor registered2 = spy(new IntermediateInterceptor());
    final List<Interceptor> interceptors = Arrays.asList(registered1, registered2);
    Interceptor real = mock(Interceptor.class);
    final Chain chain = ChainImpl.buildChain(interceptors, real);
    InOrder inOrder = Mockito.inOrder(registered1, registered2, real);
    PreparedOperation operation = mock(PreparedOperation.class);
    chain.proceed(operation);
    inOrder.verify(registered1).intercept(eq(operation), any(Chain.class));
    inOrder.verify(registered2).intercept(eq(operation), any(Chain.class));
    inOrder.verify(real).intercept(eq(operation), any(Chain.class));
}
Also used : Chain(com.pushtorefresh.storio3.Interceptor.Chain) InOrder(org.mockito.InOrder) PreparedOperation(com.pushtorefresh.storio3.operations.PreparedOperation) Interceptor(com.pushtorefresh.storio3.Interceptor) Test(org.junit.Test)

Example 8 with Chain

use of com.pushtorefresh.storio3.Interceptor.Chain in project storio by pushtorefresh.

the class ChainImplTest method buildChain_shouldThrowIfRegisteredInterceptorNull.

@Test
public void buildChain_shouldThrowIfRegisteredInterceptorNull() {
    try {
        final List<Interceptor> interceptors = Arrays.asList(null, mock(Interceptor.class));
        final Chain chain = ChainImpl.buildChain(interceptors, mock(Interceptor.class));
        chain.proceed(mock(PreparedOperation.class));
        failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessage("Interceptor should not be null");
    }
}
Also used : Chain(com.pushtorefresh.storio3.Interceptor.Chain) PreparedOperation(com.pushtorefresh.storio3.operations.PreparedOperation) Interceptor(com.pushtorefresh.storio3.Interceptor) Test(org.junit.Test)

Aggregations

PreparedOperation (com.pushtorefresh.storio3.operations.PreparedOperation)7 Test (org.junit.Test)7 Interceptor (com.pushtorefresh.storio3.Interceptor)6 Chain (com.pushtorefresh.storio3.Interceptor.Chain)5 Nullable (android.support.annotation.Nullable)1 InOrder (org.mockito.InOrder)1 Config (org.robolectric.annotation.Config)1