### Question:
IdleChannelReaperHandler extends ChannelDuplexHandler { @Override public void userEventTriggered( ChannelHandlerContext ctx, Object evt ) { if ( evt instanceof IdleStateEvent && evt == IdleStateEvent.ALL_IDLE_STATE_EVENT ) { final InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress(); final AdvertisedSocketAddress address = new AdvertisedSocketAddress( socketAddress.getHostName(), socketAddress.getPort() ); channels.remove( address ); } } IdleChannelReaperHandler( ReconnectingChannels channels ); @Override void userEventTriggered( ChannelHandlerContext ctx, Object evt );  }### Answer:
@Test public void shouldRemoveChannelViaCallback() { AdvertisedSocketAddress address = new AdvertisedSocketAddress( "localhost", 1984 ); ReconnectingChannels channels = new ReconnectingChannels(); channels.putIfAbsent( address, mock( ReconnectingChannel.class) ); IdleChannelReaperHandler reaper = new IdleChannelReaperHandler( channels ); final InetSocketAddress socketAddress = address.socketAddress(); final Channel channel = mock( Channel.class ); when( channel.remoteAddress() ).thenReturn( socketAddress ); final ChannelHandlerContext context = mock( ChannelHandlerContext.class ); when( context.channel() ).thenReturn( channel ); reaper.userEventTriggered( context, IdleStateEvent.ALL_IDLE_STATE_EVENT ); assertNull( channels.get( address ) ); }