InterceptorChain { public void fireOutbound() { this.direction = Direction.OUTBOUND; this.current = this.interceptors.size() - 1; fireCurrentOutbound(); } InterceptorChain(ChannelHandlerContext ctx, List<Interceptor> interceptors, ResourceRequest request);  InterceptorChain(ChannelHandlerContext ctx, List<Interceptor> interceptors, ResourceResponse response); ResourceRequest request(); ResourceResponse response(); void fireInbound(); void fireOutbound(); void forward(); void forward(ResourceRequest request); void forward(ResourceResponse response); void replyWith(ResourceResponse response);  }
@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); }