@Test
public void handlerReplaced() throws Exception {

    final ChannelHandler nonSslHandler = Mockito.mock(ChannelHandler.class);
    OptionalSslHandler handler = new OptionalSslHandler(sslContext) {
        @Override
        protected ChannelHandler newNonSslHandler(ChannelHandlerContext context) {
            return nonSslHandler;
        }
        @Override
        protected String newNonSslHandlerName() {
            return HANDLER_NAME;
        }
    };
    final ByteBuf payload = Unpooled.copiedBuffer("plaintext".getBytes());
    try {
        handler.decode(context, payload, null);
        verify(pipeline).replace(handler, HANDLER_NAME, nonSslHandler);
    } finally {
        payload.release();
    }
}