Search in sources :

Example 1 with BaseCheckTestSupport

use of com.puppycrawl.tools.checkstyle.BaseCheckTestSupport in project checkstyle by checkstyle.

the class AllChecksTest method testAllChecksWithDefaultConfiguration.

@Test
public void testAllChecksWithDefaultConfiguration() throws Exception {
    final String inputFilePath = getPath("InputDefaultConfig.java");
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    for (Class<?> check : CheckUtil.getCheckstyleChecks()) {
        final DefaultConfiguration checkConfig = createCheckConfig(check);
        final Checker checker;
        if (AbstractCheck.class.isAssignableFrom(check)) {
            // Checks which have Check as a parent.
            if (check.equals(ImportControlCheck.class)) {
                // ImportControlCheck must have the import control configuration file to avoid
                // violation.
                checkConfig.addAttribute("file", getPath("import-control_complete.xml"));
            }
            checker = createChecker(checkConfig);
        } else {
            // Checks which have TreeWalker as a parent.
            BaseCheckTestSupport testSupport = new BaseCheckTestSupport() {

                @Override
                protected DefaultConfiguration createCheckerConfig(Configuration config) {
                    final DefaultConfiguration dc = new DefaultConfiguration("root");
                    dc.addChild(checkConfig);
                    return dc;
                }
            };
            checker = testSupport.createChecker(checkConfig);
        }
        verify(checker, inputFilePath, expected);
    }
}
Also used : BaseCheckTestSupport(com.puppycrawl.tools.checkstyle.BaseCheckTestSupport) Checker(com.puppycrawl.tools.checkstyle.Checker) Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Aggregations

BaseCheckTestSupport (com.puppycrawl.tools.checkstyle.BaseCheckTestSupport)1 Checker (com.puppycrawl.tools.checkstyle.Checker)1 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 Test (org.junit.Test)1