Search in sources :

Example 41 with DefaultConfiguration

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

the class OneTopLevelClassCheckTest method testPackageInfoWithNoTypesDeclared.

@Test
public void testPackageInfoWithNoTypesDeclared() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(OneTopLevelClassCheck.class);
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    verify(checkConfig, getNonCompilablePath("package-info.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 42 with DefaultConfiguration

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

the class ThrowsCountCheckTest method testNotIgnorePrivateMethod.

@Test
public void testNotIgnorePrivateMethod() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(ThrowsCountCheck.class);
    checkConfig.addAttribute("ignorePrivateMethods", "false");
    final String[] expected = { "17:20: " + getCheckMessage(MSG_KEY, 5, 4), "22:20: " + getCheckMessage(MSG_KEY, 5, 4), "27:20: " + getCheckMessage(MSG_KEY, 6, 4), "35:28: " + getCheckMessage(MSG_KEY, 5, 4), "55:43: " + getCheckMessage(MSG_KEY, 5, 4) };
    verify(checkConfig, getPath("InputThrowsCount.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 43 with DefaultConfiguration

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

the class ThrowsCountCheckTest method testDefault.

@Test
public void testDefault() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(ThrowsCountCheck.class);
    final String[] expected = { "17:20: " + getCheckMessage(MSG_KEY, 5, 4), "22:20: " + getCheckMessage(MSG_KEY, 5, 4), "27:20: " + getCheckMessage(MSG_KEY, 6, 4), "55:43: " + getCheckMessage(MSG_KEY, 5, 4) };
    verify(checkConfig, getPath("InputThrowsCount.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 44 with DefaultConfiguration

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

the class VisibilityModifierCheckTest method testAllowPublicFinalFieldsInNonFinalClass.

@Test
public void testAllowPublicFinalFieldsInNonFinalClass() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(VisibilityModifierCheck.class);
    checkConfig.addAttribute("allowPublicFinalFields", "true");
    final String[] expected = { "34:20: " + getCheckMessage(MSG_KEY, "value"), "36:24: " + getCheckMessage(MSG_KEY, "bValue"), "37:31: " + getCheckMessage(MSG_KEY, "longValue") };
    verify(checkConfig, getPath("InputImmutable.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 45 with DefaultConfiguration

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

the class VisibilityModifierCheckTest method testVisibilityModifiersOfGenericFields.

@Test
public void testVisibilityModifiersOfGenericFields() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(VisibilityModifierCheck.class);
    checkConfig.addAttribute("allowPublicImmutableFields", "true");
    checkConfig.addAttribute("immutableClassCanonicalNames", "com.google.common.collect.ImmutableMap," + "java.lang.String," + "java.util.Optional," + "java.math.BigDecimal");
    final String[] expected = { "16:56: " + getCheckMessage(MSG_KEY, "perfSeries"), "17:66: " + getCheckMessage(MSG_KEY, "peopleMap"), "18:66: " + getCheckMessage(MSG_KEY, "someMap"), "19:76: " + getCheckMessage(MSG_KEY, "newMap"), "21:45: " + getCheckMessage(MSG_KEY, "optionalOfObject"), "22:35: " + getCheckMessage(MSG_KEY, "obj"), "24:19: " + getCheckMessage(MSG_KEY, "rqUID"), "25:29: " + getCheckMessage(MSG_KEY, "rqTime"), "26:45: " + getCheckMessage(MSG_KEY, "rates"), "27:50: " + getCheckMessage(MSG_KEY, "loans"), "28:60: " + getCheckMessage(MSG_KEY, "cards"), "29:60: " + getCheckMessage(MSG_KEY, "values"), "30:70: " + getCheckMessage(MSG_KEY, "permissions"), "32:38: " + getCheckMessage(MSG_KEY, "mapOfStrings"), "33:48: " + getCheckMessage(MSG_KEY, "names"), "34:48: " + getCheckMessage(MSG_KEY, "links"), "35:38: " + getCheckMessage(MSG_KEY, "presentations"), "36:48: " + getCheckMessage(MSG_KEY, "collection"), "39:73: " + getCheckMessage(MSG_KEY, "exceptions") };
    verify(checkConfig, getPath("InputVisibilityModifierGenerics.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

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