@Test
public void testOutbound() throws Exception {

    List<Interceptor> interceptors = new ArrayList<>();
    MockInterceptor interceptor1 = new MockInterceptor();
    MockInterceptor interceptor2 = new MockInterceptor();
    interceptors.add(interceptor1);
    interceptors.add(interceptor2);
    ResourceRequest request = new DefaultResourceRequest.Builder(RequestType.READ, new ResourcePath("/foo/bar")).build();
    ResourceResponse response = new DefaultResourceErrorResponse(request, ResourceErrorResponse.ErrorType.NOT_AUTHORIZED);
    EmbeddedChannel channel = new EmbeddedChannel(
            new ChannelDuplexHandler() {
                @Override
                public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
                    InterceptorChain chain = new InterceptorChain(ctx, interceptors, (ResourceResponse) msg);
                    chain.fireOutbound();
                }
            }
    );
    channel.writeInbound(request);
    ResourceRequest endRequest = (ResourceRequest) channel.readInbound();
    channel.writeAndFlush(response);
    ResourceResponse endResponse = (ResourceResponse) channel.readOutbound();
    assertThat(endResponse).isNotNull();
    assertThat(interceptor2.responses()).hasSize(1);
    assertThat(interceptor2.responses()).contains(response);
    assertThat(interceptor1.responses()).hasSize(1);
    assertThat(interceptor1.responses()).contains(response);
}