### Question:
MessageGate extends ChannelDuplexHandler { @Override public void userEventTriggered( ChannelHandlerContext ctx, Object evt ) throws Exception { if ( evt instanceof GateEvent ) { if ( GateEvent.getSuccess().equals( evt ) ) { for ( GatedWrite write : pending ) { ctx.write( write.msg, write.promise ); } ctx.channel().pipeline().remove( this ); } pending.clear(); pending = null; } else { super.userEventTriggered( ctx, evt ); } } MessageGate( Predicate<Object> gated ); @Override void userEventTriggered( ChannelHandlerContext ctx, Object evt ); @Override void write( ChannelHandlerContext ctx, Object msg, ChannelPromise promise );  }### Answer:
@Test public void shouldRemoveGateOnSuccess() throws Exception { gate.userEventTriggered( ctx, GateEvent.getSuccess() ); verify( pipeline ).remove( gate ); }
@Test public void shouldLeaveGateOnFailure() throws Exception { gate.userEventTriggered( ctx, GateEvent.getFailure() ); verify( pipeline, never() ).remove( any( ChannelHandler.class ) ); }