Search in sources :

Example 6 with BriefUtLogger

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

the class BaseCheckTestSupport method createChecker.

/**
     * Creates {@link Checker} instance based on specified {@link Configuration}.
     * @param checkConfig {@link Configuration} instance.
     * @return {@link Checker} instance.
     * @throws CheckstyleException if an exception occurs during checker configuration.
     */
protected Checker createChecker(Configuration checkConfig) throws Exception {
    final DefaultConfiguration dc = createCheckerConfig(checkConfig);
    final Checker checker = new Checker();
    // make sure the tests always run with English error messages
    // so the tests don't fail in supported locales like German
    final Locale locale = Locale.ENGLISH;
    checker.setLocaleCountry(locale.getCountry());
    checker.setLocaleLanguage(locale.getLanguage());
    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    checker.configure(dc);
    checker.addListener(new BriefUtLogger(stream));
    return checker;
}
Also used : Locale(java.util.Locale) Checker(com.puppycrawl.tools.checkstyle.Checker) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) BriefUtLogger(com.puppycrawl.tools.checkstyle.BriefUtLogger)

Example 7 with BriefUtLogger

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

the class SuppressionCommentFilterTest method createChecker.

@Override
public Checker createChecker(Configuration checkConfig) throws CheckstyleException {
    final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration");
    final DefaultConfiguration checksConfig = createCheckConfig(TreeWalker.class);
    checksConfig.addChild(createCheckConfig(FileContentsHolder.class));
    final DefaultConfiguration memberNameCheckConfig = createCheckConfig(MemberNameCheck.class);
    memberNameCheckConfig.addAttribute("id", "ignore");
    checksConfig.addChild(memberNameCheckConfig);
    final DefaultConfiguration constantNameCheckConfig = createCheckConfig(ConstantNameCheck.class);
    constantNameCheckConfig.addAttribute("id", null);
    checksConfig.addChild(constantNameCheckConfig);
    checksConfig.addChild(createCheckConfig(IllegalCatchCheck.class));
    checkerConfig.addChild(checksConfig);
    if (checkConfig != null) {
        checkerConfig.addChild(checkConfig);
    }
    final Checker checker = new Checker();
    final Locale locale = Locale.ROOT;
    checker.setLocaleCountry(locale.getCountry());
    checker.setLocaleLanguage(locale.getLanguage());
    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    checker.configure(checkerConfig);
    checker.addListener(new BriefUtLogger(stream));
    return checker;
}
Also used : Locale(java.util.Locale) Checker(com.puppycrawl.tools.checkstyle.Checker) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) BriefUtLogger(com.puppycrawl.tools.checkstyle.BriefUtLogger) FileContentsHolder(com.puppycrawl.tools.checkstyle.checks.FileContentsHolder) IllegalCatchCheck(com.puppycrawl.tools.checkstyle.checks.coding.IllegalCatchCheck)

Example 8 with BriefUtLogger

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

the class SuppressionFilterTest method testLocalFileExternalResourceContentDoesNotChange.

@Test
public void testLocalFileExternalResourceContentDoesNotChange() throws Exception {
    final DefaultConfiguration filterConfig = createCheckConfig(SuppressionFilter.class);
    filterConfig.addAttribute("file", getPath("suppressions_none.xml"));
    final DefaultConfiguration checkerConfig = new DefaultConfiguration("checkstyle_checks");
    checkerConfig.addChild(filterConfig);
    final String cacheFile = temporaryFolder.newFile().getPath();
    checkerConfig.addAttribute("cacheFile", cacheFile);
    final Checker checker = new Checker();
    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    checker.addListener(new BriefUtLogger(stream));
    checker.configure(checkerConfig);
    final String filePath = temporaryFolder.newFile("file.java").getPath();
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    verify(checker, filePath, expected);
    // One more time to use cache.
    verify(checker, filePath, expected);
}
Also used : Checker(com.puppycrawl.tools.checkstyle.Checker) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) BriefUtLogger(com.puppycrawl.tools.checkstyle.BriefUtLogger) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with BriefUtLogger

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

the class SuppressWithNearbyCommentFilterTest method createChecker.

@Override
public Checker createChecker(Configuration checkConfig) throws CheckstyleException {
    final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration");
    final DefaultConfiguration checksConfig = createCheckConfig(TreeWalker.class);
    checksConfig.addChild(createCheckConfig(FileContentsHolder.class));
    final DefaultConfiguration memberNameCheckConfig = createCheckConfig(MemberNameCheck.class);
    memberNameCheckConfig.addAttribute("id", "ignore");
    checksConfig.addChild(memberNameCheckConfig);
    final DefaultConfiguration constantNameCheckConfig = createCheckConfig(ConstantNameCheck.class);
    constantNameCheckConfig.addAttribute("id", null);
    checksConfig.addChild(constantNameCheckConfig);
    checksConfig.addChild(createCheckConfig(IllegalCatchCheck.class));
    checkerConfig.addChild(checksConfig);
    if (checkConfig != null) {
        checkerConfig.addChild(checkConfig);
    }
    final Checker checker = new Checker();
    final Locale locale = Locale.ROOT;
    checker.setLocaleCountry(locale.getCountry());
    checker.setLocaleLanguage(locale.getLanguage());
    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    checker.configure(checkerConfig);
    checker.addListener(new BriefUtLogger(stream));
    return checker;
}
Also used : Locale(java.util.Locale) Checker(com.puppycrawl.tools.checkstyle.Checker) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) BriefUtLogger(com.puppycrawl.tools.checkstyle.BriefUtLogger) FileContentsHolder(com.puppycrawl.tools.checkstyle.checks.FileContentsHolder) IllegalCatchCheck(com.puppycrawl.tools.checkstyle.checks.coding.IllegalCatchCheck)

Example 10 with BriefUtLogger

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

the class HeaderCheckTest method testCacheHeaderWithoutFile.

@Test
public void testCacheHeaderWithoutFile() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
    checkConfig.addAttribute("header", "Test");
    final DefaultConfiguration checkerConfig = new DefaultConfiguration("checkstyle_checks");
    checkerConfig.addChild(checkConfig);
    checkerConfig.addAttribute("cacheFile", temporaryFolder.newFile().getPath());
    final Checker checker = new Checker();
    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    checker.configure(checkerConfig);
    checker.addListener(new BriefUtLogger(stream));
    final String[] expected = { "1: " + getCheckMessage(MSG_MISMATCH, "Test") };
    verify(checker, getPath("InputHeader.java"), expected);
}
Also used : Checker(com.puppycrawl.tools.checkstyle.Checker) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) BriefUtLogger(com.puppycrawl.tools.checkstyle.BriefUtLogger) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

BriefUtLogger (com.puppycrawl.tools.checkstyle.BriefUtLogger)10 Checker (com.puppycrawl.tools.checkstyle.Checker)10 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)10 Locale (java.util.Locale)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 IllegalCatchCheck (com.puppycrawl.tools.checkstyle.checks.coding.IllegalCatchCheck)3 FileContentsHolder (com.puppycrawl.tools.checkstyle.checks.FileContentsHolder)2 JavadocTypeCheck (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck)1 ParameterNumberCheck (com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck)1