Search in sources :

Example 66 with DefaultConfiguration

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

the class UnnecessaryParenthesesCheckTest method testDefault.

@Test
public void testDefault() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(UnnecessaryParenthesesCheck.class);
    final String[] expected = { "5:22: " + getCheckMessage(MSG_ASSIGN), "5:29: " + getCheckMessage(MSG_EXPR), "5:31: " + getCheckMessage(MSG_IDENT, "i"), "5:46: " + getCheckMessage(MSG_ASSIGN), "6:15: " + getCheckMessage(MSG_ASSIGN), "7:14: " + getCheckMessage(MSG_IDENT, "x"), "7:17: " + getCheckMessage(MSG_ASSIGN), "8:15: " + getCheckMessage(MSG_ASSIGN), "9:14: " + getCheckMessage(MSG_IDENT, "x"), "9:17: " + getCheckMessage(MSG_ASSIGN), "12:22: " + getCheckMessage(MSG_ASSIGN), "12:30: " + getCheckMessage(MSG_IDENT, "i"), "12:46: " + getCheckMessage(MSG_ASSIGN), "16:17: " + getCheckMessage(MSG_LITERAL, "0"), "26:11: " + getCheckMessage(MSG_ASSIGN), "30:11: " + getCheckMessage(MSG_ASSIGN), "32:11: " + getCheckMessage(MSG_ASSIGN), "34:11: " + getCheckMessage(MSG_ASSIGN), "35:16: " + getCheckMessage(MSG_IDENT, "a"), "36:14: " + getCheckMessage(MSG_IDENT, "a"), "36:20: " + getCheckMessage(MSG_IDENT, "b"), "36:26: " + getCheckMessage(MSG_LITERAL, "600"), "36:40: " + getCheckMessage(MSG_LITERAL, "12.5f"), "36:56: " + getCheckMessage(MSG_IDENT, "arg2"), "37:14: " + getCheckMessage(MSG_STRING, "\"this\""), "37:25: " + getCheckMessage(MSG_STRING, "\"that\""), "38:11: " + getCheckMessage(MSG_ASSIGN), "38:14: " + getCheckMessage(MSG_STRING, "\"this is a really, really...\""), "40:16: " + getCheckMessage(MSG_RETURN), "44:21: " + getCheckMessage(MSG_LITERAL, "1"), "44:26: " + getCheckMessage(MSG_LITERAL, "13.5"), "45:22: " + getCheckMessage(MSG_LITERAL, "true"), "46:17: " + getCheckMessage(MSG_IDENT, "b"), "50:17: " + getCheckMessage(MSG_ASSIGN), "52:11: " + getCheckMessage(MSG_ASSIGN), "54:16: " + getCheckMessage(MSG_RETURN), "64:13: " + getCheckMessage(MSG_EXPR), "68:16: " + getCheckMessage(MSG_EXPR), "73:19: " + getCheckMessage(MSG_EXPR), "74:23: " + getCheckMessage(MSG_LITERAL, "4000"), "79:19: " + getCheckMessage(MSG_ASSIGN), "81:11: " + getCheckMessage(MSG_ASSIGN), "81:16: " + getCheckMessage(MSG_LITERAL, "3"), "82:39: " + getCheckMessage(MSG_ASSIGN) };
    verify(checkConfig, getPath("InputUnnecessaryParentheses.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 67 with DefaultConfiguration

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

the class RegexpHeaderCheckTest method testRegexpHeader.

@Test
public void testRegexpHeader() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(RegexpHeaderCheck.class);
    checkConfig.addAttribute("headerFile", getPath("regexp.header"));
    final String[] expected = { "3: " + getCheckMessage(MSG_HEADER_MISMATCH, "// Created: 2002") };
    verify(checkConfig, getPath("InputRegexpHeader7.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 68 with DefaultConfiguration

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

the class RegexpHeaderCheckTest method testDefaultConfiguration.

@Test
public void testDefaultConfiguration() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(RegexpHeaderCheck.class);
    createChecker(checkConfig);
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    verify(checkConfig, getPath("InputRegexpHeader1.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 69 with DefaultConfiguration

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

the class RegexpHeaderCheckTest method testEmptyMultiline.

@Test
public void testEmptyMultiline() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(RegexpHeaderCheck.class);
    checkConfig.addAttribute("headerFile", getPath("regexp.header2"));
    checkConfig.addAttribute("multiLines", "");
    final String[] expected = { "1: " + getCheckMessage(MSG_HEADER_MISSING) };
    verify(checkConfig, getPath("InputRegexpSmallHeader.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 70 with DefaultConfiguration

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

the class AvoidStarImportCheckTest method testExcludes.

@Test
public void testExcludes() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(AvoidStarImportCheck.class);
    checkConfig.addAttribute("excludes", "java.io,java.lang,javax.swing.WindowConstants.*, javax.swing.WindowConstants");
    // allow the java.io/java.lang,javax.swing.WindowConstants star imports
    final String[] expected2 = { "7: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.checks.imports.*"), "28: " + getCheckMessage(MSG_KEY, "java.io.File.*") };
    verify(checkConfig, getPath("InputAvoidStarImport.java"), expected2);
}
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