Search in sources :

Example 1 with DefaultConfiguration

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

the class CustomImportOrderCheckTest method testOrderRuleWithOneGroup.

@Test
public void testOrderRuleWithOneGroup() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(CustomImportOrderCheck.class);
    checkConfig.addAttribute("thirdPartyPackageRegExp", "org.");
    checkConfig.addAttribute("customImportOrderRules", "STANDARD_JAVA_PACKAGE");
    checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true");
    final String[] expected = { "4: " + getCheckMessage(MSG_LEX, "java.awt.Button.ABORT", "java.io.File.createTempFile"), "7: " + getCheckMessage(MSG_LEX, "java.util.List", "javax.swing.WindowConstants.*"), "8: " + getCheckMessage(MSG_LEX, "java.util.StringTokenizer", "javax.swing.WindowConstants.*"), "9: " + getCheckMessage(MSG_LEX, "java.util.*", "javax.swing.WindowConstants.*"), "10: " + getCheckMessage(MSG_LEX, "java.util.concurrent.AbstractExecutorService", "javax.swing.WindowConstants.*"), "11: " + getCheckMessage(MSG_LEX, "java.util.concurrent.*", "javax.swing.WindowConstants.*"), "14: " + getCheckMessage(MSG_LEX, "com.*", "com.puppycrawl.tools.*"), "16: " + getCheckMessage(MSG_LEX, "com.google.common.base.*", "com.puppycrawl.tools.*") };
    verify(checkConfig, getPath("InputCustomImportOrder2.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 2 with DefaultConfiguration

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

the class CustomImportOrderCheckTest method testWithoutThirdPartyPackage.

@Test
public void testWithoutThirdPartyPackage() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(CustomImportOrderCheck.class);
    checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true");
    checkConfig.addAttribute("separateLineBetweenGroups", "true");
    checkConfig.addAttribute("customImportOrderRules", "SAME_PACKAGE(3)###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE###STATIC");
    final String[] expected = { "4: " + getCheckMessage(MSG_LINE_SEPARATOR, "org.junit.*") };
    verify(checkConfig, getPath("InputCustomImportOrderThirdPartyPackage.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 3 with DefaultConfiguration

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

the class CustomImportOrderCheckTest method testImportsContainingJava.

@Test
public void testImportsContainingJava() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(CustomImportOrderCheck.class);
    checkConfig.addAttribute("customImportOrderRules", "STANDARD_JAVA_PACKAGE###THIRD_PARTY_PACKAGE");
    final String[] expected = { "5: " + getCheckMessage(MSG_LINE_SEPARATOR, "com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck") };
    verify(checkConfig, getPath("InputCustomImportOrderImportsContainingJava.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 4 with DefaultConfiguration

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

the class IllegalImportCheckTest method testWithSupplied.

@Test
public void testWithSupplied() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(IllegalImportCheck.class);
    checkConfig.addAttribute("illegalPkgs", "java.io");
    final String[] expected = { "9:1: " + getCheckMessage(MSG_KEY, "java.io.*"), "23:1: " + getCheckMessage(MSG_KEY, "java.io.File.listRoots"), "27:1: " + getCheckMessage(MSG_KEY, "java.io.File.createTempFile") };
    verify(checkConfig, getPath("InputIllegalImport.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 5 with DefaultConfiguration

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

the class IllegalImportCheckTest method testWithDefault.

@Test
public void testWithDefault() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(IllegalImportCheck.class);
    final String[] expected = { "15:1: " + getCheckMessage(MSG_KEY, "sun.applet.*"), "28:1: " + getCheckMessage(MSG_KEY, "sun.*") };
    verify(checkConfig, getPath("InputIllegalImport.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Aggregations

DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)1896 Test (org.junit.Test)1138 Test (org.junit.jupiter.api.Test)702 File (java.io.File)376 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)50 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)38 Checker (com.puppycrawl.tools.checkstyle.Checker)18 ExpectedDependencies (com.github.sevntu.checkstyle.domain.ExpectedDependencies)10 Violation (com.puppycrawl.tools.checkstyle.api.Violation)8 Locale (java.util.Locale)8 BriefUtLogger (com.puppycrawl.tools.checkstyle.BriefUtLogger)6 IllegalCatchCheck (com.puppycrawl.tools.checkstyle.checks.coding.IllegalCatchCheck)6 TreeSet (java.util.TreeSet)6 TreeWalker (com.puppycrawl.tools.checkstyle.TreeWalker)4 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)4 FileText (com.puppycrawl.tools.checkstyle.api.FileText)4 List (java.util.List)3 DependencyInformationConsumerInjector (com.github.sevntu.checkstyle.common.DependencyInformationConsumerInjector)2 MethodCallDependencyCheckstyleModule (com.github.sevntu.checkstyle.module.MethodCallDependencyCheckstyleModule)2 BaseCheckTestSupport (com.puppycrawl.tools.checkstyle.BaseCheckTestSupport)2