Search in sources :

Example 31 with Configuration

use of com.puppycrawl.tools.checkstyle.api.Configuration in project checkstyle by checkstyle.

the class OneTopLevelClassTest method goodTest.

@Test
public void goodTest() throws Exception {
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    final Configuration checkConfig = getCheckConfig("OneTopLevelClass");
    final String filePath = getPath("InputOneTopLevelClassGood.java");
    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(checkConfig, filePath, expected, warnList);
}
Also used : Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) Test(org.junit.Test)

Example 32 with Configuration

use of com.puppycrawl.tools.checkstyle.api.Configuration in project checkstyle by checkstyle.

the class OneTopLevelClassTest method badTest.

@Test
public void badTest() throws Exception {
    final Class<OneTopLevelClassCheck> clazz = OneTopLevelClassCheck.class;
    final String messageKey = "one.top.level.class";
    final String[] expected = { "25: " + getCheckMessage(clazz, messageKey, "NoSuperClone"), "33: " + getCheckMessage(clazz, messageKey, "InnerClone"), "50: " + getCheckMessage(clazz, messageKey, "CloneWithTypeArguments"), "55: " + getCheckMessage(clazz, messageKey, "CloneWithTypeArgumentsAndNoSuper"), "60: " + getCheckMessage(clazz, messageKey, "MyClassWithGenericSuperMethod"), "77: " + getCheckMessage(clazz, messageKey, "AnotherClass") };
    final Configuration checkConfig = getCheckConfig("OneTopLevelClass");
    final String filePath = getPath("InputOneTopLevelClassBasic.java");
    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(checkConfig, filePath, expected, warnList);
}
Also used : Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) OneTopLevelClassCheck(com.puppycrawl.tools.checkstyle.checks.design.OneTopLevelClassCheck) Test(org.junit.Test)

Example 33 with Configuration

use of com.puppycrawl.tools.checkstyle.api.Configuration in project checkstyle by checkstyle.

the class UpperEllTest method upperEllTest.

@Test
public void upperEllTest() throws Exception {
    final String[] expected = { "6:36: Should use uppercase 'L'.", "12:27: Should use uppercase 'L'.", "14:32: Should use uppercase 'L'.", "17:19: Should use uppercase 'L'.", "21:29: Should use uppercase 'L'.", "22:22: Should use uppercase 'L'.", "25:15: Should use uppercase 'L'.", "34:47: Should use uppercase 'L'.", "40:31: Should use uppercase 'L'.", "42:36: Should use uppercase 'L'.", "45:23: Should use uppercase 'L'.", "50:33: Should use uppercase 'L'.", "51:26: Should use uppercase 'L'.", "56:23: Should use uppercase 'L'.", "65:48: Should use uppercase 'L'.", "71:39: Should use uppercase 'L'.", "73:44: Should use uppercase 'L'.", "76:31: Should use uppercase 'L'.", "80:41: Should use uppercase 'L'.", "81:34: Should use uppercase 'L'.", "84:27: Should use uppercase 'L'.", "97:46: Should use uppercase 'L'.", "99:29: Should use uppercase 'L'.", "100:22: Should use uppercase 'L'." };
    final Configuration checkConfig = getCheckConfig("UpperEll");
    final String filePath = getPath("InputUpperEll.java");
    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(checkConfig, filePath, expected, warnList);
}
Also used : Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) Test(org.junit.Test)

Example 34 with Configuration

use of com.puppycrawl.tools.checkstyle.api.Configuration in project checkstyle by checkstyle.

the class TypeNameTest method typeNameTest.

@Test
public void typeNameTest() throws Exception {
    final Configuration checkConfig = getCheckConfig("TypeName");
    final String msgKey = "name.invalidPattern";
    final String format = "^[A-Z][a-zA-Z0-9]*$";
    final String[] expected = { "3:7: " + getCheckMessage(checkConfig.getMessages(), msgKey, "inputHeaderClass", format), "5:22: " + getCheckMessage(checkConfig.getMessages(), msgKey, "InputHeader___Interface", format), "7:17: " + getCheckMessage(checkConfig.getMessages(), msgKey, "inputHeaderEnum", format), "9:11: " + getCheckMessage(checkConfig.getMessages(), msgKey, "NoValid$Name", format), "11:11: " + getCheckMessage(checkConfig.getMessages(), msgKey, "$NoValidName", format), "13:11: " + getCheckMessage(checkConfig.getMessages(), msgKey, "NoValidName$", format), "19:7: " + getCheckMessage(checkConfig.getMessages(), msgKey, "_ValidName", format), "21:7: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Valid_Name", format), "23:7: " + getCheckMessage(checkConfig.getMessages(), msgKey, "ValidName_", format), "27:11: " + getCheckMessage(checkConfig.getMessages(), msgKey, "_Foo", format), "29:11: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Fo_o", format), "31:11: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Foo_", format), "33:11: " + getCheckMessage(checkConfig.getMessages(), msgKey, "$Foo", format), "35:11: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Fo$o", format), "37:11: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Foo$", format), "41:6: " + getCheckMessage(checkConfig.getMessages(), msgKey, "_FooEnum", format), "43:6: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Foo_Enum", format), "45:6: " + getCheckMessage(checkConfig.getMessages(), msgKey, "FooEnum_", format), "47:6: " + getCheckMessage(checkConfig.getMessages(), msgKey, "$FooEnum", format), "49:6: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Foo$Enum", format), "51:6: " + getCheckMessage(checkConfig.getMessages(), msgKey, "FooEnum$", format), "53:7: " + getCheckMessage(checkConfig.getMessages(), msgKey, "aaa", format), "55:11: " + getCheckMessage(checkConfig.getMessages(), msgKey, "bbb", format), "57:6: " + getCheckMessage(checkConfig.getMessages(), msgKey, "ccc", format), "61:12: " + getCheckMessage(checkConfig.getMessages(), msgKey, "_Annotation", format), "63:12: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Annot_ation", format), "65:12: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Annotation_", format), "67:12: " + getCheckMessage(checkConfig.getMessages(), msgKey, "$Annotation", format), "69:12: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Annot$ation", format), "71:12: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Annotation$", format) };
    final String filePath = getPath("InputTypeName.java");
    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(checkConfig, filePath, expected, warnList);
}
Also used : Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) Test(org.junit.Test)

Example 35 with Configuration

use of com.puppycrawl.tools.checkstyle.api.Configuration in project checkstyle by checkstyle.

the class MethodNameTest method methodNameTest.

@Test
public void methodNameTest() throws Exception {
    final Configuration checkConfig = getCheckConfig("MethodName");
    final String msgKey = "name.invalidPattern";
    final String format = "^[a-z][a-z0-9][a-zA-Z0-9_]*$";
    final String[] expected = { "11:14: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Foo", format), "12:14: " + getCheckMessage(checkConfig.getMessages(), msgKey, "fOo", format), "14:14: " + getCheckMessage(checkConfig.getMessages(), msgKey, "f$o", format), "15:14: " + getCheckMessage(checkConfig.getMessages(), msgKey, "f_oo", format), "16:14: " + getCheckMessage(checkConfig.getMessages(), msgKey, "f", format), "17:14: " + getCheckMessage(checkConfig.getMessages(), msgKey, "fO", format), "21:22: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Foo", format), "22:22: " + getCheckMessage(checkConfig.getMessages(), msgKey, "fOo", format), "24:22: " + getCheckMessage(checkConfig.getMessages(), msgKey, "f$o", format), "25:22: " + getCheckMessage(checkConfig.getMessages(), msgKey, "f_oo", format), "26:22: " + getCheckMessage(checkConfig.getMessages(), msgKey, "f", format), "27:22: " + getCheckMessage(checkConfig.getMessages(), msgKey, "fO", format), "32:22: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Foo", format), "33:22: " + getCheckMessage(checkConfig.getMessages(), msgKey, "fOo", format), "35:22: " + getCheckMessage(checkConfig.getMessages(), msgKey, "f$o", format), "36:22: " + getCheckMessage(checkConfig.getMessages(), msgKey, "f_oo", format), "37:22: " + getCheckMessage(checkConfig.getMessages(), msgKey, "f", format), "38:22: " + getCheckMessage(checkConfig.getMessages(), msgKey, "fO", format), "44:14: " + getCheckMessage(checkConfig.getMessages(), msgKey, "Foo", format), "45:14: " + getCheckMessage(checkConfig.getMessages(), msgKey, "fOo", format), "47:14: " + getCheckMessage(checkConfig.getMessages(), msgKey, "f$o", format), "48:14: " + getCheckMessage(checkConfig.getMessages(), msgKey, "f_oo", format), "49:14: " + getCheckMessage(checkConfig.getMessages(), msgKey, "f", format), "50:14: " + getCheckMessage(checkConfig.getMessages(), msgKey, "fO", format) };
    final String filePath = getPath("InputMethodName.java");
    final Integer[] warnList = getLinesWithWarn(filePath);
    verify(checkConfig, filePath, expected, warnList);
}
Also used : Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) Test(org.junit.Test)

Aggregations

Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)307 Test (org.junit.jupiter.api.Test)179 Test (org.junit.Test)100 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)34 Properties (java.util.Properties)21 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)16 File (java.io.File)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 PropertiesExpander (com.puppycrawl.tools.checkstyle.PropertiesExpander)11 Checker (com.puppycrawl.tools.checkstyle.Checker)9 HashSet (java.util.HashSet)8 InputSource (org.xml.sax.InputSource)7 OneTopLevelClassCheck (com.puppycrawl.tools.checkstyle.checks.design.OneTopLevelClassCheck)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 ConfigurationLoader (com.puppycrawl.tools.checkstyle.ConfigurationLoader)5 URI (java.net.URI)5 MethodParamPadCheck (com.puppycrawl.tools.checkstyle.checks.whitespace.MethodParamPadCheck)4 Set (java.util.Set)4 ModuleFactory (com.puppycrawl.tools.checkstyle.ModuleFactory)3