Repository: netty/netty
File: transport/src/test/java/io/netty/channel/AbstractEventLoopTest.java (Java)

Code before:
                    public void initChannel(SocketChannel ch) {
                    }
                }).handler(new ChannelInitializer<ServerSocketChannel>() {
                    @Override
                    public void initChannel(ServerSocketChannel ch) {
                        ch.pipeline().addLast(new TestChannelHandler());
                        ch.pipeline().addLast(eventExecutorGroup, new TestChannelHandler2());
                    }
                })
                .bind(0).awaitUninterruptibly();

        EventExecutor executor = future.channel().pipeline().context(TestChannelHandler2.class).executor();
        EventExecutor executor1 = future.channel().pipeline().context(TestChannelHandler.class).executor();
        future.channel().deregister().awaitUninterruptibly();
        Channel channel = group2.register(future.channel()).awaitUninterruptibly().channel();
        EventExecutor executorNew = channel.pipeline().context(TestChannelHandler.class).executor();
        assertNotSame(executor1, executorNew);
        assertSame(executor, future.channel().pipeline().context(TestChannelHandler2.class).executor());
    }

    /**
     * Test for https://github.com/netty/netty/issues/14923
     */
    @ParameterizedTest
    @EnumSource(DeregisterMethod.class)
    void tesrReregisterOnChannelHandlerContext(DeregisterMethod method) throws Exception {
        EventLoopGroup bossGroup = newEventLoopGroup();
        EventLoopGroup workerGroup = newEventLoopGroup();
        AtomicReference<Throwable> throwable = new AtomicReference<>();
        try {
            ServerBootstrap b = new ServerBootstrap();
            ReRegisterHandler reRegisterHandler = new ReRegisterHandler(workerGroup, method, throwable);
            b.group(bossGroup, workerGroup)
                    .channel(newChannel())
                    .childHandler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        public void initChannel(SocketChannel ch) {
                            ChannelPipeline p = ch.pipeline();
                            p.addLast("logging", new LoggingHandler());
                            p.addLast(reRegisterHandler);
                        }
                    });

            ChannelFuture f = b.bind(0).sync();

            Channel client = new Bootstrap()
                    .group(workerGroup)
                    .channel(newSocketChannel())
                    .handler(new ChannelInboundHandlerAdapter() {
                        @Override
                        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

Review comment (suggestion):
```suggestion
    void testReregisterOnChannelHandlerContext(DeregisterMethod method) throws Exception {
```

Code after:
                    public void initChannel(SocketChannel ch) {
                    }
                }).handler(new ChannelInitializer<ServerSocketChannel>() {
                    @Override
                    public void initChannel(ServerSocketChannel ch) {
                        ch.pipeline().addLast(new TestChannelHandler());
                        ch.pipeline().addLast(eventExecutorGroup, new TestChannelHandler2());
                    }
                })
                .bind(0).awaitUninterruptibly();

        EventExecutor executor = future.channel().pipeline().context(TestChannelHandler2.class).executor();
        EventExecutor executor1 = future.channel().pipeline().context(TestChannelHandler.class).executor();
        future.channel().deregister().awaitUninterruptibly();
        Channel channel = group2.register(future.channel()).awaitUninterruptibly().channel();
        EventExecutor executorNew = channel.pipeline().context(TestChannelHandler.class).executor();
        assertNotSame(executor1, executorNew);
        assertSame(executor, future.channel().pipeline().context(TestChannelHandler2.class).executor());
    }

    /**
     * Test for https://github.com/netty/netty/issues/14923
     */
    @ParameterizedTest
    @EnumSource(DeregisterMethod.class)
    void testReregisterOnChannelHandlerContext(DeregisterMethod method) throws Exception {
        EventLoopGroup bossGroup = newEventLoopGroup();
        EventLoopGroup workerGroup = newEventLoopGroup();
        AtomicReference<Throwable> throwable = new AtomicReference<>();
        try {
            ServerBootstrap b = new ServerBootstrap();
            ReRegisterHandler reRegisterHandler = new ReRegisterHandler(workerGroup, method, throwable);
            b.group(bossGroup, workerGroup)
                    .channel(newChannel())
                    .childHandler(new ChannelInitializer<SocketChannel>() {
                        @Override
                        public void initChannel(SocketChannel ch) {
                            ChannelPipeline p = ch.pipeline();
                            p.addLast("logging", new LoggingHandler());
                            p.addLast(reRegisterHandler);
                        }
                    });

            ChannelFuture f = b.bind(0).sync();

            Channel client = new Bootstrap()
                    .group(workerGroup)
                    .channel(newSocketChannel())
                    .handler(new ChannelInboundHandlerAdapter() {
                        @Override
                        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {