Search in sources :

Example 71 with DefaultConfiguration

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

the class AvoidStarImportCheckTest method testDefaultOperation.

@Test
public void testDefaultOperation() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(AvoidStarImportCheck.class);
    final String[] expected = { "7: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.checks.imports.*"), "9: " + getCheckMessage(MSG_KEY, "java.io.*"), "10: " + getCheckMessage(MSG_KEY, "java.lang.*"), "25: " + getCheckMessage(MSG_KEY, "javax.swing.WindowConstants.*"), "26: " + getCheckMessage(MSG_KEY, "javax.swing.WindowConstants.*"), "28: " + getCheckMessage(MSG_KEY, "java.io.File.*") };
    verify(checkConfig, getPath("InputAvoidStarImport.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 72 with DefaultConfiguration

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

the class AvoidStaticImportCheckTest method testInnerClassMemberExcludesStar.

@Test
public void testInnerClassMemberExcludesStar() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(AvoidStaticImportCheck.class);
    // should mask com.puppycrawl.tools.checkstyle.imports.InputAvoidStaticImportNestedClass.
    // InnerClass.one
    checkConfig.addAttribute("excludes", "com.puppycrawl.tools.checkstyle.checks.imports." + "InputAvoidStaticImportNestedClass.InnerClass.*");
    final String[] expected = { "23: " + getCheckMessage(MSG_KEY, "java.io.File.listRoots"), "25: " + getCheckMessage(MSG_KEY, "javax.swing.WindowConstants.*"), "26: " + getCheckMessage(MSG_KEY, "javax.swing.WindowConstants.*"), "27: " + getCheckMessage(MSG_KEY, "java.io.File.createTempFile"), "28: " + getCheckMessage(MSG_KEY, "java.io.File.pathSeparator"), "29: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.checks.imports." + "InputAvoidStaticImportNestedClass.InnerClass") };
    verify(checkConfig, getPath("InputAvoidStaticImport.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 73 with DefaultConfiguration

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

the class AvoidStaticImportCheckTest method testStarExcludes.

@Test
public void testStarExcludes() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(AvoidStaticImportCheck.class);
    checkConfig.addAttribute("excludes", "java.io.File.*,sun.net.ftpclient.FtpClient.*");
    // allow the "java.io.File.*" AND "sun.net.ftpclient.FtpClient.*" star imports
    final String[] expected = { "25: " + getCheckMessage(MSG_KEY, "javax.swing.WindowConstants.*"), "26: " + getCheckMessage(MSG_KEY, "javax.swing.WindowConstants.*"), "29: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.checks.imports." + "InputAvoidStaticImportNestedClass.InnerClass"), "30: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.checks.imports." + "InputAvoidStaticImportNestedClass.InnerClass.one") };
    verify(checkConfig, getPath("InputAvoidStaticImport.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 74 with DefaultConfiguration

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

the class AvoidStaticImportCheckTest method testBogusMemberExcludes.

@Test
public void testBogusMemberExcludes() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(AvoidStaticImportCheck.class);
    // should NOT mask anything
    checkConfig.addAttribute("excludes", "java.io.File.listRoots.listRoots, javax.swing.WindowConstants, javax.swing.*," + "sun.net.ftpclient.FtpClient.*FtpClient, sun.net.ftpclient.FtpClientjunk," + " java.io.File.listRootsmorejunk");
    final String[] expected = { "23: " + getCheckMessage(MSG_KEY, "java.io.File.listRoots"), "25: " + getCheckMessage(MSG_KEY, "javax.swing.WindowConstants.*"), "26: " + getCheckMessage(MSG_KEY, "javax.swing.WindowConstants.*"), "27: " + getCheckMessage(MSG_KEY, "java.io.File.createTempFile"), "28: " + getCheckMessage(MSG_KEY, "java.io.File.pathSeparator"), "29: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.checks.imports." + "InputAvoidStaticImportNestedClass.InnerClass"), "30: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.checks.imports." + "InputAvoidStaticImportNestedClass.InnerClass.one") };
    verify(checkConfig, getPath("InputAvoidStaticImport.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 75 with DefaultConfiguration

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

the class AtclauseOrderCheckTest method testCorrect.

@Test
public void testCorrect() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(AtclauseOrderCheck.class);
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    verify(checkConfig, getPath("InputCorrectAtClauseOrder.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