@Test(timeout = 5000)
public void testChannelInitializerException() throws Exception {

    final IllegalStateException exception = new IllegalStateException();
    final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
    final CountDownLatch latch = new CountDownLatch(1);
    EmbeddedChannel channel = new EmbeddedChannel(new ChannelInitializer<Channel>() {
        @Override
        protected void initChannel(Channel ch) throws Exception {
            throw exception;
        }
        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            super.exceptionCaught(ctx, cause);
            error.set(cause);
            latch.countDown();
        }
    });
    latch.await();
    assertFalse(channel.isActive());
    assertSame(exception, error.get());
}