Search in sources :

Example 46 with DefaultConfiguration

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

the class VisibilityModifierCheckTest method testNullModifiers.

@Test
public void testNullModifiers() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(VisibilityModifierCheck.class);
    checkConfig.addAttribute("allowPublicImmutableFields", "true");
    final String[] expected = { "11:50: " + getCheckMessage(MSG_KEY, "i") };
    verify(checkConfig, getPath("InputNullModifiers.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 47 with DefaultConfiguration

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

the class VisibilityModifierCheckTest method testCustomAnnotationPatterns.

@Test
public void testCustomAnnotationPatterns() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(VisibilityModifierCheck.class);
    checkConfig.addAttribute("ignoreAnnotationCanonicalNames", "com.puppycrawl.tools.checkstyle.checks.design." + "InputAnnotatedVisibility.CustomAnnotation");
    final String[] expected = { "16:28: " + getCheckMessage(MSG_KEY, "publicJUnitRule"), "19:28: " + getCheckMessage(MSG_KEY, "fqPublicJUnitRule"), "22:19: " + getCheckMessage(MSG_KEY, "googleCommonsAnnotatedPublic"), "25:12: " + getCheckMessage(MSG_KEY, "googleCommonsAnnotatedPackage"), "28:22: " + getCheckMessage(MSG_KEY, "googleCommonsAnnotatedProtected"), "31:19: " + getCheckMessage(MSG_KEY, "fqGoogleCommonsAnnotatedPublic"), "34:12: " + getCheckMessage(MSG_KEY, "fqGoogleCommonsAnnotatedPackage"), "37:22: " + getCheckMessage(MSG_KEY, "fqGoogleCommonsAnnotatedProtected"), "48:19: " + getCheckMessage(MSG_KEY, "unannotatedPublic"), "49:12: " + getCheckMessage(MSG_KEY, "unannotatedPackage"), "50:22: " + getCheckMessage(MSG_KEY, "unannotatedProtected"), "59:35: " + getCheckMessage(MSG_KEY, "publicJUnitClassRule"), "62:35: " + getCheckMessage(MSG_KEY, "fqPublicJUnitClassRule") };
    verify(checkConfig, getPath("InputAnnotatedVisibility.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 48 with DefaultConfiguration

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

the class VisibilityModifierCheckTest method testImmutableStarImportFalseNegative.

@Test
public void testImmutableStarImportFalseNegative() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(VisibilityModifierCheck.class);
    checkConfig.addAttribute("allowPublicImmutableFields", "true");
    checkConfig.addAttribute("immutableClassCanonicalNames", "java.util.Arrays");
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    verify(checkConfig, getPath("InputImmutableStarImport.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 49 with DefaultConfiguration

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

the class VisibilityModifierCheckTest method testIgnoreAnnotationNoPattern.

@Test
public void testIgnoreAnnotationNoPattern() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(VisibilityModifierCheck.class);
    checkConfig.addAttribute("ignoreAnnotationCanonicalNames", "");
    final String[] expected = { "16:28: " + getCheckMessage(MSG_KEY, "publicJUnitRule"), "19:28: " + getCheckMessage(MSG_KEY, "fqPublicJUnitRule"), "22:19: " + getCheckMessage(MSG_KEY, "googleCommonsAnnotatedPublic"), "25:12: " + getCheckMessage(MSG_KEY, "googleCommonsAnnotatedPackage"), "28:22: " + getCheckMessage(MSG_KEY, "googleCommonsAnnotatedProtected"), "31:19: " + getCheckMessage(MSG_KEY, "fqGoogleCommonsAnnotatedPublic"), "34:12: " + getCheckMessage(MSG_KEY, "fqGoogleCommonsAnnotatedPackage"), "37:22: " + getCheckMessage(MSG_KEY, "fqGoogleCommonsAnnotatedProtected"), "40:19: " + getCheckMessage(MSG_KEY, "customAnnotatedPublic"), "43:12: " + getCheckMessage(MSG_KEY, "customAnnotatedPackage"), "46:22: " + getCheckMessage(MSG_KEY, "customAnnotatedProtected"), "48:19: " + getCheckMessage(MSG_KEY, "unannotatedPublic"), "49:12: " + getCheckMessage(MSG_KEY, "unannotatedPackage"), "50:22: " + getCheckMessage(MSG_KEY, "unannotatedProtected"), "59:35: " + getCheckMessage(MSG_KEY, "publicJUnitClassRule"), "62:35: " + getCheckMessage(MSG_KEY, "fqPublicJUnitClassRule") };
    verify(checkConfig, getPath("InputAnnotatedVisibility.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 50 with DefaultConfiguration

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

the class VisibilityModifierCheckTest method getChecker.

private Checker getChecker() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(VisibilityModifierCheck.class);
    checkConfig.addAttribute("publicMemberPattern", "^f[A-Z][a-zA-Z0-9]*$");
    return createChecker(checkConfig);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration)

Aggregations

DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)1004 Test (org.junit.Test)986 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)47 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)31 File (java.io.File)22 Checker (com.puppycrawl.tools.checkstyle.Checker)16 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 BriefUtLogger (com.puppycrawl.tools.checkstyle.BriefUtLogger)10 Locale (java.util.Locale)5 Method (java.lang.reflect.Method)4 IllegalCatchCheck (com.puppycrawl.tools.checkstyle.checks.coding.IllegalCatchCheck)3 IOException (java.io.IOException)3 BaseCheckTestSupport (com.puppycrawl.tools.checkstyle.BaseCheckTestSupport)2 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)2 LocalizedMessage (com.puppycrawl.tools.checkstyle.api.LocalizedMessage)2 FileContentsHolder (com.puppycrawl.tools.checkstyle.checks.FileContentsHolder)2 RandomAccessFile (java.io.RandomAccessFile)2 PropertiesExpander (com.puppycrawl.tools.checkstyle.PropertiesExpander)1 TokenTypes (com.puppycrawl.tools.checkstyle.api.TokenTypes)1 MSG_KEY (com.puppycrawl.tools.checkstyle.checks.AvoidEscapedUnicodeCharactersCheck.MSG_KEY)1