static Optional<CommentWidget> getCommentWidget(ITemplateContext context) {
        final ApplicationContext appCtx = SpringContextUtils.getApplicationContext(context);
        SystemConfigurableEnvironmentFetcher environmentFetcher =
            appCtx.getBean(SystemConfigurableEnvironmentFetcher.class);
        var commentSetting = environmentFetcher.fetchComment()
            .blockOptional()
            .orElseThrow();
        var globalEnabled = isTrue(commentSetting.getEnable());
        if (!globalEnabled) {
            return Optional.empty();
        }

        if (Contexts.isWebContext(context)) {
            IWebContext webContext = Contexts.asWebContext(context);
            Object attributeValue = webContext.getExchange()
                .getAttributeValue(CommentWidget.ENABLE_COMMENT_ATTRIBUTE);
            Boolean enabled = DefaultConversionService.getSharedInstance()
                .convert(attributeValue, Boolean.class);
            if (isFalse(enabled)) {
                return Optional.empty();
            }
        }

        ExtensionGetter extensionGetter = appCtx.getBean(ExtensionGetter.class);
        return extensionGetter.getEnabledExtensions(CommentWidget.class)
            .next()
            .blockOptional();
    }
@Test
    void getCommentWidget() {
        when(applicationContext.getBean(eq(SystemConfigurableEnvironmentFetcher.class)))
            .thenReturn(environmentFetcher);
        SystemSetting.Comment commentSetting = mock(SystemSetting.Comment.class);
        when(environmentFetcher.fetchComment())
            .thenReturn(Mono.just(commentSetting));

        CommentWidget commentWidget = mock(CommentWidget.class);
        when(extensionGetter.getEnabledExtensions(CommentWidget.class))
            .thenReturn(Flux.just(commentWidget));
        WebEngineContext webContext = mock(WebEngineContext.class);
        var evaluationContext = mock(ThymeleafEvaluationContext.class);
        when(webContext.getVariable(
            eq(ThymeleafEvaluationContext.THYMELEAF_EVALUATION_CONTEXT_CONTEXT_VARIABLE_NAME)))
            .thenReturn(evaluationContext);
        when(evaluationContext.getApplicationContext()).thenReturn(applicationContext);
        IWebExchange webExchange = mock(IWebExchange.class);
        when(webContext.getExchange()).thenReturn(webExchange);

        // comment disabled
        when(commentSetting.getEnable()).thenReturn(true);
        assertThat(
            CommentEnabledVariableProcessor.getCommentWidget(webContext).isPresent()).isTrue();

        // comment enabled
        when(commentSetting.getEnable()).thenReturn(false);
        assertThat(
            CommentEnabledVariableProcessor.getCommentWidget(webContext).isPresent()).isFalse();

        // comment enabled and ENABLE_COMMENT_ATTRIBUTE is true
        when(commentSetting.getEnable()).thenReturn(true);
        when(webExchange.getAttributeValue(CommentWidget.ENABLE_COMMENT_ATTRIBUTE))
            .thenReturn(true);
        assertThat(
            CommentEnabledVariableProcessor.getCommentWidget(webContext).isPresent()).isTrue();

        // comment enabled and ENABLE_COMMENT_ATTRIBUTE is false
        when(commentSetting.getEnable()).thenReturn(true);
        when(webExchange.getAttributeValue(CommentWidget.ENABLE_COMMENT_ATTRIBUTE))
            .thenReturn(false);
        assertThat(
            CommentEnabledVariableProcessor.getCommentWidget(webContext).isPresent()).isFalse();

        // comment enabled and ENABLE_COMMENT_ATTRIBUTE is null
        when(commentSetting.getEnable()).thenReturn(true);
        when(webExchange.getAttributeValue(CommentWidget.ENABLE_COMMENT_ATTRIBUTE))
            .thenReturn(null);
        assertThat(
            CommentEnabledVariableProcessor.getCommentWidget(webContext).isPresent()).isTrue();

        // comment enabled and ENABLE_COMMENT_ATTRIBUTE is 'false'
        when(commentSetting.getEnable()).thenReturn(true);
        when(webExchange.getAttributeValue(CommentWidget.ENABLE_COMMENT_ATTRIBUTE))
            .thenReturn("false");
        assertThat(
            CommentEnabledVariableProcessor.getCommentWidget(webContext).isPresent()).isFalse();
    }