Search in sources :

Example 6 with DefaultConfiguration

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

the class ImportControlCheckTest method testRegExpInPackage.

// all import-control_pkg-re* files should be equivalent so use one test for all
private void testRegExpInPackage(String file) throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
    checkConfig.addAttribute("file", getPath(file));
    final String[] expected = { "5:1: " + getCheckMessage(MSG_DISALLOWED, "java.io.File") };
    verify(checkConfig, getPath("InputImportControl.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration)

Example 7 with DefaultConfiguration

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

the class ImportControlCheckTest method testEmpty.

@Test
public void testEmpty() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class);
    checkConfig.addAttribute("file", "   ");
    final String[] expected = { "1:1: " + getCheckMessage(MSG_MISSING_FILE) };
    verify(checkConfig, getPath("InputImportControl.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 8 with DefaultConfiguration

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

the class CustomImportOrderCheckTest method testNoPackage2.

@Test
public void testNoPackage2() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(CustomImportOrderCheck.class);
    checkConfig.addAttribute("customImportOrderRules", "STATIC###THIRD_PARTY_PACKAGE");
    checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true");
    checkConfig.addAttribute("separateLineBetweenGroups", "true");
    createChecker(checkConfig);
    final String[] expected = { "3: " + getCheckMessage(MSG_LINE_SEPARATOR, "com.puppycrawl.tools.checkstyle.utils.AnnotationUtility.containsAnnotation"), "7: " + getCheckMessage(MSG_LINE_SEPARATOR, "com.sun.accessibility.internal.resources.*"), "11: " + getCheckMessage(MSG_LINE_SEPARATOR, "java.util.Arrays"), "19: " + getCheckMessage(MSG_LINE_SEPARATOR, "org.apache.commons.beanutils.converters.ArrayConverter") };
    verify(checkConfig, getPath("InputCustomImportOrderNoPackage2.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 9 with DefaultConfiguration

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

the class CustomImportOrderCheckTest method testDefaultPackage2.

@Test
public void testDefaultPackage2() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(CustomImportOrderCheck.class);
    checkConfig.addAttribute("thirdPartyPackageRegExp", "com|org");
    checkConfig.addAttribute("customImportOrderRules", "STATIC###SAME_PACKAGE(3)###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE");
    checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true");
    final String[] expected = { "7: " + getCheckMessage(MSG_LEX, "java.awt.Button.ABORT", "java.io.File.createTempFile"), "10: " + getCheckMessage(MSG_ORDER, STD, THIRD, "java.awt.Button"), "11: " + getCheckMessage(MSG_ORDER, STD, THIRD, "java.awt.Frame"), "12: " + getCheckMessage(MSG_ORDER, STD, THIRD, "java.awt.Dialog"), "13: " + getCheckMessage(MSG_ORDER, STD, THIRD, "java.awt.event.ActionEvent"), "14: " + getCheckMessage(MSG_ORDER, STD, THIRD, "javax.swing.JComponent"), "15: " + getCheckMessage(MSG_ORDER, STD, THIRD, "javax.swing.JTable"), "16: " + getCheckMessage(MSG_ORDER, STD, THIRD, "java.io.File"), "17: " + getCheckMessage(MSG_ORDER, STD, THIRD, "java.io.IOException"), "18: " + getCheckMessage(MSG_ORDER, STD, THIRD, "java.io.InputStream"), "19: " + getCheckMessage(MSG_ORDER, STD, THIRD, "java.io.Reader"), "23: " + getCheckMessage(MSG_LEX, "com.google.common.*", "com.puppycrawl.tools.*") };
    verify(checkConfig, getNonCompilablePath("InputDefaultPackage.java"), expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Test(org.junit.Test)

Example 10 with DefaultConfiguration

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

the class CustomImportOrderCheckTest method testWithoutLineSeparator2.

@Test
public void testWithoutLineSeparator2() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(CustomImportOrderCheck.class);
    checkConfig.addAttribute("separateLineBetweenGroups", "false");
    checkConfig.addAttribute("customImportOrderRules", "STATIC###STANDARD_JAVA_PACKAGE");
    checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true");
    final String[] expected = { "4: " + getCheckMessage(MSG_LEX, "java.io.File.createTempFile", "javax.swing.WindowConstants.*"), "8: " + getCheckMessage(MSG_LEX, "com.*", "com.puppycrawl.tools.*") };
    verify(checkConfig, getPath("InputCustomImportOrder_NoSeparator.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