### Question:
SocketTransport implements NettyServer.ProtocolInitializer { @Override public ChannelInitializer<Channel> channelInitializer() { return new ChannelInitializer<Channel>() { @Override public void initChannel( Channel ch ) { ch.config().setAllocator( PooledByteBufAllocator.DEFAULT ); BoltChannel boltChannel = newBoltChannel( ch ); connectionTracker.add( boltChannel ); ch.closeFuture().addListener( future -> connectionTracker.remove( boltChannel ) ); throttleGroup.install( ch ); ch.closeFuture().addListener( future -> throttleGroup.uninstall( ch ) ); TransportSelectionHandler transportSelectionHandler = new TransportSelectionHandler( boltChannel, sslCtx, encryptionRequired, false, logging, boltProtocolFactory ); ch.pipeline().addLast( transportSelectionHandler ); } }; } SocketTransport( String connector, ListenSocketAddress address, SslContext sslCtx, boolean encryptionRequired,
            LogProvider logging, TransportThrottleGroup throttleGroup,
            BoltProtocolFactory boltProtocolFactory, NetworkConnectionTracker connectionTracker ); @Override ChannelInitializer<Channel> channelInitializer(); @Override ListenSocketAddress address();  }### Answer:
@Test void shouldManageChannelsInChannelInitializer() { NetworkConnectionTracker connectionTracker = mock( NetworkConnectionTracker.class ); SocketTransport socketTransport = newSocketTransport( connectionTracker, NO_THROTTLE ); EmbeddedChannel channel = new EmbeddedChannel( socketTransport.channelInitializer() ); ArgumentCaptor<TrackedNetworkConnection> captor = ArgumentCaptor.forClass( TrackedNetworkConnection.class ); verify( connectionTracker ).add( captor.capture() ); verify( connectionTracker, never() ).remove( any() ); channel.close(); verify( connectionTracker ).remove( captor.getValue() ); }
@Test void shouldManageThrottlersInChannelInitializer() { TransportThrottleGroup throttleGroup = mock( TransportThrottleGroup.class ); SocketTransport socketTransport = newSocketTransport( NetworkConnectionTracker.NO_OP, throttleGroup ); EmbeddedChannel channel = new EmbeddedChannel( socketTransport.channelInitializer() ); verify( throttleGroup ).install( channel ); verify( throttleGroup, never() ).uninstall( channel ); channel.close(); verify( throttleGroup ).uninstall( channel ); }
@Test void shouldInstallTransportSelectionHandler() { SocketTransport socketTransport = newSocketTransport( NetworkConnectionTracker.NO_OP, NO_THROTTLE ); EmbeddedChannel channel = new EmbeddedChannel( socketTransport.channelInitializer() ); TransportSelectionHandler handler = channel.pipeline().get( TransportSelectionHandler.class ); assertNotNull( handler ); }