### Question:
Pipeline { public Packet send(final Connection connection, final Packet packet) { final Iterator<OutboundHandler> iter = outboundHandlers.iterator(); final AtomicReference<Packet> processedPacket = new AtomicReference<>(); final PipelineContext ctx = new PipelineContext() { @Override public void next(final Packet newPacket) { if (iter.hasNext()) { final OutboundHandler handler = iter.next(); handler.beforeSendPacket(newPacket, this); } else { processedPacket.set(newPacket); } } @Override public Version getVersion() { return connection.getVersion(); } @Override public InetSocketAddress getPeerAddress() { return connection.getPeerAddress(); } @Override public State getState() { return connection.getState(); } @Override public void setState(final State state) { ((InternalConnection) connection).setState(state); } @Override public Packet sendPacket(final Packet p) { return connection.sendPacket(p); } @Override public FullPacket send(final Frame... frames) { return connection.send(frames); } @Override public void closeConnection( final TransportError error, final FrameType frameType, final String msg) { connection.close(error, frameType, msg); } }; if (iter.hasNext()) { final OutboundHandler handler = iter.next(); handler.beforeSendPacket(packet, ctx); } return processedPacket.get(); } Pipeline(
      final List<InboundHandler> inboundHandlers, final List<OutboundHandler> outboundHandlers); void onPacket(final Connection connection, final Packet packet); Packet send(final Connection connection, final Packet packet);  }### Answer:
@Test public void outboundPropagation() { final OutboundHandler handler1 = spy(new PropagatingOutboundHandler()); final OutboundHandler handler2 = spy(new PropagatingOutboundHandler()); final OutboundHandler handler3 = spy(new PropagatingOutboundHandler()); final Pipeline pipeline = new Pipeline(List.of(), List.of(handler1, handler2, handler3)); pipeline.send(connection, packet); verify(handler1).beforeSendPacket(eq(packet), any(PipelineContext.class)); verify(handler2).beforeSendPacket(eq(packet), any(PipelineContext.class)); verify(handler3).beforeSendPacket(eq(packet), any(PipelineContext.class)); }
@Test public void outboundNonPropagation() { final OutboundHandler handler1 = spy(new PropagatingOutboundHandler()); final OutboundHandler handler2 = spy(new NonPropagatingOutboundHandler()); final OutboundHandler handler3 = spy(new PropagatingOutboundHandler()); final Pipeline pipeline = new Pipeline(List.of(), List.of(handler1, handler2, handler3)); pipeline.send(connection, packet); verify(handler1).beforeSendPacket(eq(packet), any(PipelineContext.class)); verify(handler2).beforeSendPacket(eq(packet), any(PipelineContext.class)); verifyZeroInteractions(handler3); }