Search in sources :

Example 81 with DefaultConfiguration

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

the class CyclomaticComplexityCheckTest method testSwitchBlockAsSingleDecisionPointSetToTrue.

@Test
public void testSwitchBlockAsSingleDecisionPointSetToTrue() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(CyclomaticComplexityCheck.class);
    checkConfig.addAttribute("max", "0");
    checkConfig.addAttribute("switchBlockAsSingleDecisionPoint", "true");
    final String[] expected = { "4:5: " + getCheckMessage(MSG_KEY, 2, 0) };
    verify(checkConfig, getPath("InputComplexitySwitchBlocks.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 82 with DefaultConfiguration

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

the class CyclomaticComplexityCheckTest method test.

@Test
public void test() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(CyclomaticComplexityCheck.class);
    checkConfig.addAttribute("max", "0");
    final String[] expected = { "4:5: " + getCheckMessage(MSG_KEY, 2, 0), "7:17: " + getCheckMessage(MSG_KEY, 2, 0), "17:5: " + getCheckMessage(MSG_KEY, 6, 0), "27:5: " + getCheckMessage(MSG_KEY, 3, 0), "34:5: " + getCheckMessage(MSG_KEY, 5, 0), "48:5: " + getCheckMessage(MSG_KEY, 3, 0), "58:5: " + getCheckMessage(MSG_KEY, 3, 0), "67:5: " + getCheckMessage(MSG_KEY, 3, 0), "76:5: " + getCheckMessage(MSG_KEY, 1, 0), "79:13: " + getCheckMessage(MSG_KEY, 2, 0) };
    verify(checkConfig, getPath("InputComplexity.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 83 with DefaultConfiguration

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

the class JavaNCSSCheckTest method test.

@Test
public void test() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(JavaNCSSCheck.class);
    checkConfig.addAttribute("methodMaximum", "0");
    checkConfig.addAttribute("classMaximum", "1");
    checkConfig.addAttribute("fileMaximum", "2");
    final String[] expected = { "2:1: " + getCheckMessage(MSG_FILE, 39, 2), "9:1: " + getCheckMessage(MSG_CLASS, 22, 1), "14:5: " + getCheckMessage(MSG_METHOD, 2, 0), "21:5: " + getCheckMessage(MSG_METHOD, 4, 0), "30:5: " + getCheckMessage(MSG_METHOD, 12, 0), "42:13: " + getCheckMessage(MSG_METHOD, 2, 0), "49:5: " + getCheckMessage(MSG_CLASS, 2, 1), "56:1: " + getCheckMessage(MSG_CLASS, 10, 1), "61:5: " + getCheckMessage(MSG_METHOD, 8, 0), "80:1: " + getCheckMessage(MSG_CLASS, 4, 1), "81:5: " + getCheckMessage(MSG_METHOD, 1, 0), "82:5: " + getCheckMessage(MSG_METHOD, 1, 0), "83:5: " + getCheckMessage(MSG_METHOD, 1, 0) };
    verify(checkConfig, getPath("InputJavaNCSS.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 84 with DefaultConfiguration

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

the class NPathComplexityCheckTest method testCalculation.

@Test
public void testCalculation() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(NPathComplexityCheck.class);
    checkConfig.addAttribute("max", "0");
    final String[] expected = { "4:5: " + getCheckMessage(MSG_KEY, 2, 0), "7:17: " + getCheckMessage(MSG_KEY, 2, 0), "17:5: " + getCheckMessage(MSG_KEY, 5, 0), "27:5: " + getCheckMessage(MSG_KEY, 3, 0), "34:5: " + getCheckMessage(MSG_KEY, 7, 0), "48:5: " + getCheckMessage(MSG_KEY, 3, 0), "58:5: " + getCheckMessage(MSG_KEY, 3, 0), "67:5: " + getCheckMessage(MSG_KEY, 3, 0), "76:5: " + getCheckMessage(MSG_KEY, 1, 0), "79:13: " + getCheckMessage(MSG_KEY, 2, 0) };
    verify(checkConfig, getPath("InputComplexity.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 85 with DefaultConfiguration

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

the class NPathComplexityCheckTest method testIntegerOverflow.

@Test
public void testIntegerOverflow() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(NPathComplexityCheck.class);
    checkConfig.addAttribute("max", "0");
    final long largerThanMaxInt = 3_486_784_401L;
    final String[] expected = { "9:5: " + getCheckMessage(MSG_KEY, largerThanMaxInt, 0) };
    verify(checkConfig, getPath("InputComplexityOverflow.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