Search in sources :

Example 31 with DefaultConfiguration

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

the class VariableDeclarationUsageDistanceCheckTest method testIgnoreFinalOption.

@Test
public void testIgnoreFinalOption() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(VariableDeclarationUsageDistanceCheck.class);
    checkConfig.addAttribute("allowedDistance", "1");
    checkConfig.addAttribute("ignoreVariablePattern", "");
    checkConfig.addAttribute("validateBetweenScopes", "true");
    checkConfig.addAttribute("ignoreFinal", "true");
    final String[] expected = { "30: " + getCheckMessage(MSG_KEY_EXT, "a", 2, 1), "38: " + getCheckMessage(MSG_KEY_EXT, "temp", 2, 1), "44: " + getCheckMessage(MSG_KEY_EXT, "temp", 2, 1), "57: " + getCheckMessage(MSG_KEY_EXT, "count", 2, 1), "71: " + getCheckMessage(MSG_KEY_EXT, "count", 4, 1), "96: " + getCheckMessage(MSG_KEY_EXT, "arg", 2, 1), "144: " + getCheckMessage(MSG_KEY_EXT, "m", 3, 1), "145: " + getCheckMessage(MSG_KEY_EXT, "n", 2, 1), "184: " + getCheckMessage(MSG_KEY_EXT, "result", 2, 1), "219: " + getCheckMessage(MSG_KEY_EXT, "t", 5, 1), "222: " + getCheckMessage(MSG_KEY_EXT, "c", 3, 1), "223: " + getCheckMessage(MSG_KEY_EXT, "d2", 3, 1), "260: " + getCheckMessage(MSG_KEY_EXT, "selected", 2, 1), "261: " + getCheckMessage(MSG_KEY_EXT, "model", 2, 1), "287: " + getCheckMessage(MSG_KEY_EXT, "sw", 2, 1), "300: " + getCheckMessage(MSG_KEY_EXT, "wh", 2, 1), "343: " + getCheckMessage(MSG_KEY_EXT, "green", 2, 1), "344: " + getCheckMessage(MSG_KEY_EXT, "blue", 3, 1), "454: " + getCheckMessage(MSG_KEY_EXT, "aOpt", 3, 1), "455: " + getCheckMessage(MSG_KEY_EXT, "bOpt", 2, 1), "471: " + getCheckMessage(MSG_KEY_EXT, "l1", 3, 1), "471: " + getCheckMessage(MSG_KEY_EXT, "l2", 2, 1), "479: " + getCheckMessage(MSG_KEY_EXT, "myOption", 7, 1), "491: " + getCheckMessage(MSG_KEY_EXT, "myOption", 6, 1), "504: " + getCheckMessage(MSG_KEY_EXT, "count", 4, 1), "505: " + getCheckMessage(MSG_KEY_EXT, "files", 2, 1), "540: " + getCheckMessage(MSG_KEY_EXT, "id", 2, 1), "542: " + getCheckMessage(MSG_KEY_EXT, "parentId", 3, 1), "891: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 1), "901: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 1), "967: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 1) };
    verify(checkConfig, getPath("InputVariableDeclarationUsageDistance.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 32 with DefaultConfiguration

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

the class DesignForExtensionCheckTest method testOverridableMethods.

@Test
public void testOverridableMethods() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(DesignForExtensionCheck.class);
    final String[] expected = { "6:9: " + getCheckMessage(MSG_KEY, "A", "foo1"), "30:9: " + getCheckMessage(MSG_KEY, "A", "foo8"), "35:9: " + getCheckMessage(MSG_KEY, "A", "foo9"), "42:9: " + getCheckMessage(MSG_KEY, "A", "foo10"), "49:9: " + getCheckMessage(MSG_KEY, "A", "foo11"), "54:9: " + getCheckMessage(MSG_KEY, "A", "foo12"), "61:9: " + getCheckMessage(MSG_KEY, "A", "foo13"), "68:9: " + getCheckMessage(MSG_KEY, "A", "foo14"), "90:9: " + getCheckMessage(MSG_KEY, "A", "foo22"), "96:9: " + getCheckMessage(MSG_KEY, "A", "foo23"), "110:9: " + getCheckMessage(MSG_KEY, "A", "foo26"), "117:9: " + getCheckMessage(MSG_KEY, "A", "foo27") };
    verify(checkConfig, getPath("InputDesignForExtensionOverridableMethods.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 33 with DefaultConfiguration

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

the class DesignForExtensionCheckTest method testNativeMethods.

@Test
public void testNativeMethods() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(DesignForExtensionCheck.class);
    checkConfig.addAttribute("ignoredAnnotations", "Deprecated");
    final String[] expected = { "8:5: " + getCheckMessage(MSG_KEY, "InputDesignForExtensionNativeMethods", "foo1") };
    verify(checkConfig, getPath("InputDesignForExtensionNativeMethods.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 34 with DefaultConfiguration

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

the class DesignForExtensionCheckTest method testIt.

@Test
public void testIt() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(DesignForExtensionCheck.class);
    final String[] expected = { "46:5: " + getCheckMessage(MSG_KEY, "InputDesignForExtension", "doh"), "100:9: " + getCheckMessage(MSG_KEY, "anotherNonFinalClass", "someMethod") };
    verify(checkConfig, getPath("InputDesignForExtension.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 35 with DefaultConfiguration

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

the class FinalClassCheckTest method testClassWithPrivateCtorAndNestedExtendingSubclassWithoutPackage.

@Test
public void testClassWithPrivateCtorAndNestedExtendingSubclassWithoutPackage() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(FinalClassCheck.class);
    final String[] expected = { "7: " + getCheckMessage(MSG_KEY, "C") };
    verify(checkConfig, getNonCompilablePath("InputClassWithPrivateCtorWithNestedExtendingClassWithoutPackage.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