/*
 * Copyright (c) 2023 - 2024. KeyWare.Co.Ltd All rights reserved.
 * 项目名称：Java 信息安全性设计准则
 * 项目描述：用于检查Java源代码的安全性设计准则的Sonarqube插件
 * 版权说明：本软件属北京关键科技股份有限公司所有，在未获得北京关键科技股份有限公司正式授权情况下，任何企业和个人，不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。
 */
package com.keyware.sonar.java.rules;

import org.junit.jupiter.api.Test;
import org.sonar.api.rule.RuleKey;
import org.sonar.java.checks.verifier.TestCheckRegistrarContext;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * TODO JavaFileCheckRegistrarTest
 *
 * @author GuoXin
 * @date 2024/1/6
 */
public class JavaFileCheckRegistrarTest {

    @Test
    void checkRegisteredRulesKeysAndClasses() {
        TestCheckRegistrarContext context = new TestCheckRegistrarContext();

        JavaFileCheckRegistrar registrar = new JavaFileCheckRegistrar();
        registrar.register(context);

        assertThat(context.mainRuleKeys).extracting(RuleKey::toString).containsExactly(
                /*"mycompany-java:SpringControllerRequestMappingEntity",
                "mycompany-java:AvoidAnnotation",
                "mycompany-java:AvoidBrandInMethodNames",
                "mycompany-java:AvoidMethodDeclaration",
                "mycompany-java:AvoidSuperClass",
                "mycompany-java:AvoidTreeList",
                "mycompany-java:AvoidMethodWithSameTypeInArgument",
                "mycompany-java:SecurityAnnotationMandatory"*/
                "keyware-java-security-design:ABCVarNameChecker"
        );

        assertThat(context.mainCheckClasses).extracting(Class::getSimpleName).containsExactly(
                /*"SpringControllerRequestMappingEntityRule",
                "AvoidAnnotationRule",
                "AvoidBrandInMethodNamesRule",
                "AvoidMethodDeclarationRule",
                "AvoidSuperClassRule",
                "AvoidTreeListRule",
                "MyCustomSubscriptionRule",
                "SecurityAnnotationMandatoryRule"*/
                "ABCVarNameChecker"
        );

        assertThat(context.testRuleKeys).extracting(RuleKey::toString).containsExactly(
                /*"mycompany-java:NoIfStatementInTests"*/
        );

        assertThat(context.testCheckClasses).extracting(Class::getSimpleName).containsExactly(
                /*"NoIfStatementInTestsRule"*/
        );
    }

}
