@Test
public void sslHandlerReplaced() throws Exception {

    final SslHandler sslHandler = Mockito.mock(SslHandler.class);
    OptionalSslHandler handler = new OptionalSslHandler(sslContext) {
        @Override
        protected SslHandler newSslHandler(ChannelHandlerContext context, SslContext sslContext) {
            return sslHandler;
        }
        @Override
        protected String newSslHandlerName() {
            return SSL_HANDLER_NAME;
        }
    };
    final ByteBuf payload = Unpooled.wrappedBuffer(new byte[] { 22, 3, 1, 0, 5 });
    try {
        handler.decode(context, payload, null);
        verify(pipeline).replace(handler, SSL_HANDLER_NAME, sslHandler);
    } finally {
        payload.release();
    }
}