Search in sources :

Example 11 with AbstractCheck

use of com.puppycrawl.tools.checkstyle.api.AbstractCheck in project checkstyle by checkstyle.

the class AllChecksTest method testRequiredTokensAreSubsetOfDefaultTokens.

@Test
public void testRequiredTokensAreSubsetOfDefaultTokens() throws Exception {
    for (Class<?> check : CheckUtil.getCheckstyleChecks()) {
        if (AbstractCheck.class.isAssignableFrom(check)) {
            final AbstractCheck testedCheck = (AbstractCheck) check.getDeclaredConstructor().newInstance();
            final int[] defaultTokens = testedCheck.getDefaultTokens();
            final int[] requiredTokens = testedCheck.getRequiredTokens();
            assertWithMessage("%s's required tokens must be a subset of default tokens.", check.getName()).that(isSubset(requiredTokens, defaultTokens)).isTrue();
        }
    }
}
Also used : AbstractCheck(com.puppycrawl.tools.checkstyle.api.AbstractCheck) Test(org.junit.jupiter.api.Test)

Example 12 with AbstractCheck

use of com.puppycrawl.tools.checkstyle.api.AbstractCheck in project sevntu.checkstyle by sevntu-checkstyle.

the class AllChecksTest method testDefaultTokensAreSubsetOfAcceptableTokens.

@Test
public void testDefaultTokensAreSubsetOfAcceptableTokens() throws Exception {
    for (Class<?> check : CheckUtil.getCheckstyleChecks()) {
        if (AbstractCheck.class.isAssignableFrom(check)) {
            final AbstractCheck testedCheck = (AbstractCheck) check.getDeclaredConstructor().newInstance();
            final int[] defaultTokens = testedCheck.getDefaultTokens();
            final int[] acceptableTokens = testedCheck.getAcceptableTokens();
            if (!isSubset(defaultTokens, acceptableTokens)) {
                final String errorMessage = String.format(Locale.ROOT, "%s's default tokens must be a subset" + " of acceptable tokens.", check.getName());
                Assert.fail(errorMessage);
            }
        }
    }
}
Also used : AbstractCheck(com.puppycrawl.tools.checkstyle.api.AbstractCheck) Test(org.junit.Test)

Example 13 with AbstractCheck

use of com.puppycrawl.tools.checkstyle.api.AbstractCheck in project sevntu.checkstyle by sevntu-checkstyle.

the class AllChecksTest method testRequiredTokensAreSubsetOfDefaultTokens.

@Test
public void testRequiredTokensAreSubsetOfDefaultTokens() throws Exception {
    for (Class<?> check : CheckUtil.getCheckstyleChecks()) {
        if (AbstractCheck.class.isAssignableFrom(check)) {
            final AbstractCheck testedCheck = (AbstractCheck) check.getDeclaredConstructor().newInstance();
            final int[] defaultTokens = testedCheck.getDefaultTokens();
            final int[] requiredTokens = testedCheck.getRequiredTokens();
            if (!isSubset(requiredTokens, defaultTokens)) {
                final String errorMessage = String.format(Locale.ROOT, "%s's required tokens must be a subset" + " of default tokens.", check.getName());
                Assert.fail(errorMessage);
            }
        }
    }
}
Also used : AbstractCheck(com.puppycrawl.tools.checkstyle.api.AbstractCheck) Test(org.junit.Test)

Aggregations

AbstractCheck (com.puppycrawl.tools.checkstyle.api.AbstractCheck)13 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)4 Test (org.junit.jupiter.api.Test)4 ModuleFactory (com.puppycrawl.tools.checkstyle.ModuleFactory)3 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)2 AbstractJavadocCheck (com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Node (org.w3c.dom.Node)2 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)1 Checker (com.puppycrawl.tools.checkstyle.Checker)1 ConfigurationLoader (com.puppycrawl.tools.checkstyle.ConfigurationLoader)1 IgnoredModulesOptions (com.puppycrawl.tools.checkstyle.ConfigurationLoader.IgnoredModulesOptions)1 PropertiesExpander (com.puppycrawl.tools.checkstyle.PropertiesExpander)1 PropertyType (com.puppycrawl.tools.checkstyle.PropertyType)1 XdocsPropertyType (com.puppycrawl.tools.checkstyle.XdocsPropertyType)1