diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStarImportCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStarImportCheck.java index f2b4bafc9..2b0c37784 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStarImportCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStarImportCheck.java @@ -65,6 +65,13 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes; public class AvoidStarImportCheck extends Check { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY = "import.avoidStar"; + /** the packages/classes to exempt from this check. */ private final List excludes = Lists.newArrayList(); @@ -143,7 +150,7 @@ public class AvoidStarImportCheck { final FullIdent name = FullIdent.createFullIdent(startingDot); if (isStaredImport(name) && !excludes.contains(name.getText())) { - log(startingDot.getLineNo(), "import.avoidStar", name.getText()); + log(startingDot.getLineNo(), MSG_KEY, name.getText()); } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStaticImportCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStaticImportCheck.java index f6ee26881..67394ca43 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStaticImportCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStaticImportCheck.java @@ -65,6 +65,13 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes; public class AvoidStaticImportCheck extends Check { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY = "import.avoidStatic"; + /** the classes/static members to exempt from this check. */ private String[] excludes = new String[0]; @@ -98,7 +105,7 @@ public class AvoidStaticImportCheck final FullIdent name = FullIdent.createFullIdent(startingDot); if ((null != name) && !isExempt(name.getText())) { - log(startingDot.getLineNo(), "import.avoidStatic", name.getText()); + log(startingDot.getLineNo(), MSG_KEY, name.getText()); } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/CustomImportOrderCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/CustomImportOrderCheck.java index 3add1ead9..a21fc58ba 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/CustomImportOrderCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/CustomImportOrderCheck.java @@ -166,6 +166,30 @@ import com.puppycrawl.tools.checkstyle.api.Utils; public class CustomImportOrderCheck extends Check { + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_LINE_SEPARATOR = "custom.import.order.line.separator"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_LEX = "custom.import.order.lex"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_NONGROUP_IMPORT = "custom.import.order.nongroup.import"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_ORDER = "custom.import.order"; + /** STATIC group name */ private static final String STATIC_RULE_GROUP = "STATIC"; @@ -356,7 +380,7 @@ public class CustomImportOrderCheck extends Check if (separateLineBetweenGroups && previousImport != null && !hasEmptyLineBefore(importObject.getLineNumber())) { - log(importObject.getLineNumber(), "custom.import.order.line.separator", + log(importObject.getLineNumber(), MSG_LINE_SEPARATOR, fullImportIdent); } currentGroup = nextGroup; @@ -378,7 +402,7 @@ public class CustomImportOrderCheck extends Check fullImportIdent, currentGroup) && !(compareImports(fullImportIdent, previousImport) >= 0)) { - log(importObject.getLineNumber(), "custom.import.order.lex", fullImportIdent); + log(importObject.getLineNumber(), MSG_LEX, fullImportIdent); } previousImport = fullImportIdent; } @@ -394,10 +418,10 @@ public class CustomImportOrderCheck extends Check private void logWrongImportGroupOrder(int currentImportLine, String importGroup) { if (NON_GROUP_RULE_GROUP.equals(importGroup)) { - log(currentImportLine, "custom.import.order.nongroup.import"); + log(currentImportLine, MSG_NONGROUP_IMPORT); } else { - log(currentImportLine, "custom.import.order", importGroup); + log(currentImportLine, MSG_ORDER, importGroup); } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheck.java index c6db7121d..1ef1de17c 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheck.java @@ -61,6 +61,13 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes; public class IllegalImportCheck extends Check { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY = "import.illegal"; + /** list of illegal packages */ private String[] illegalPkgs; @@ -107,7 +114,7 @@ public class IllegalImportCheck if (isIllegalImport(imp.getText())) { log(ast.getLineNo(), ast.getColumnNo(), - "import.illegal", + MSG_KEY, imp.getText()); } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java index 2df21914d..9fcebd888 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheck.java @@ -43,6 +43,25 @@ import org.apache.commons.beanutils.ConversionException; */ public class ImportControlCheck extends Check { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_MISSING_FILE = "import.control.missing.file"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_UNKNOWN_PKG = "import.control.unknown.pkg"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_DISALLOWED = "import.control.disallowed"; + /** The root package controller. */ private PkgControl root; /** The package doing the import. */ @@ -81,13 +100,13 @@ public class ImportControlCheck extends Check final DetailAST nameAST = ast.getLastChild().getPreviousSibling(); final FullIdent full = FullIdent.createFullIdent(nameAST); if (root == null) { - log(nameAST, "import.control.missing.file"); + log(nameAST, MSG_MISSING_FILE); } else { inPkg = full.getText(); currentLeaf = root.locateFinest(inPkg); if (currentLeaf == null) { - log(nameAST, "import.control.unknown.pkg"); + log(nameAST, MSG_UNKNOWN_PKG); } } } @@ -104,7 +123,7 @@ public class ImportControlCheck extends Check final AccessResult access = currentLeaf.checkAccess(imp.getText(), inPkg); if (!AccessResult.ALLOWED.equals(access)) { - log(ast, "import.control.disallowed", imp.getText()); + log(ast, MSG_DISALLOWED, imp.getText()); } } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java index f13331c07..1c44434a9 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java @@ -93,6 +93,18 @@ public class ImportOrderCheck extends AbstractOptionCheck { + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_SEPARATION = "import.separation"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_ORDERING = "import.ordering"; + /** the special wildcard that catches all remaining groups. */ private static final String WILDCARD_GROUP_NAME = "*"; @@ -295,7 +307,7 @@ public class ImportOrderCheck // This check should be made more robust to handle // comments and imports that span more than one line. if ((line - lastImportLine) < 2) { - log(line, "import.separation", name); + log(line, MSG_SEPARATION, name); } } } @@ -303,7 +315,7 @@ public class ImportOrderCheck doVisitTokenInSameGroup(isStatic, previous, name, line); } else { - log(line, "import.ordering", name); + log(line, MSG_ORDERING, name); } lastGroup = groupIdx; @@ -330,7 +342,7 @@ public class ImportOrderCheck if (getAbstractOption().equals(ImportOrderOption.INFLOW)) { // out of lexicographic order if (compare(lastImport, name, caseSensitive) > 0) { - log(line, "import.ordering", name); + log(line, MSG_ORDERING, name); } } else { @@ -348,7 +360,7 @@ public class ImportOrderCheck previous; if (shouldFireError) { - log(line, "import.ordering", name); + log(line, MSG_ORDERING, name); } } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheck.java index 92e18df04..211bc24e8 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheck.java @@ -54,6 +54,25 @@ import java.util.Set; public class RedundantImportCheck extends Check { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_LANG = "import.lang"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_SAME = "import.same"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_DUPLICATE = "import.duplicate"; + /** name of package in file */ private String pkgName; /** set of the imports */ @@ -97,18 +116,18 @@ public class RedundantImportCheck else if (ast.getType() == TokenTypes.IMPORT) { final FullIdent imp = FullIdent.createFullIdentBelow(ast); if (fromPackage(imp.getText(), "java.lang")) { - log(ast.getLineNo(), ast.getColumnNo(), "import.lang", + log(ast.getLineNo(), ast.getColumnNo(), MSG_LANG, imp.getText()); } else if (fromPackage(imp.getText(), pkgName)) { - log(ast.getLineNo(), ast.getColumnNo(), "import.same", + log(ast.getLineNo(), ast.getColumnNo(), MSG_SAME, imp.getText()); } // Check for a duplicate import for (FullIdent full : imports) { if (imp.getText().equals(full.getText())) { log(ast.getLineNo(), ast.getColumnNo(), - "import.duplicate", full.getLineNo(), + MSG_DUPLICATE, full.getLineNo(), imp.getText()); } } @@ -123,7 +142,7 @@ public class RedundantImportCheck for (FullIdent full : staticImports) { if (imp.getText().equals(full.getText())) { log(ast.getLineNo(), ast.getColumnNo(), - "import.duplicate", full.getLineNo(), imp.getText()); + MSG_DUPLICATE, full.getLineNo(), imp.getText()); } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java index 451677215..215612481 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheck.java @@ -52,6 +52,13 @@ import java.util.regex.Pattern; */ public class UnusedImportsCheck extends Check { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY = "import.unused"; + /** regex to match class names. */ private static final Pattern CLASS_NAME = Pattern.compile( "((:?[\\p{L}_$][\\p{L}\\p{N}_$]*\\.)*[\\p{L}_$][\\p{L}\\p{N}_$]*)"); @@ -99,7 +106,7 @@ public class UnusedImportsCheck extends Check if (!referenced.contains(Utils.baseClassname(imp.getText()))) { log(imp.getLineNo(), imp.getColumnNo(), - "import.unused", imp.getText()); + MSG_KEY, imp.getText()); } } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStarImportTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStarImportTest.java index 66d5fe42e..5ae48abbf 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStarImportTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStarImportTest.java @@ -23,6 +23,8 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import java.io.File; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck.MSG_KEY; + public class AvoidStarImportTest extends BaseCheckTestSupport { @@ -33,12 +35,12 @@ public class AvoidStarImportTest final DefaultConfiguration checkConfig = createCheckConfig(AvoidStarImportCheck.class); final String[] expected = { - "7: Using the '.*' form of import should be avoided - com.puppycrawl.tools.checkstyle.imports.*.", - "9: Using the '.*' form of import should be avoided - java.io.*.", - "10: Using the '.*' form of import should be avoided - java.lang.*.", - "25: Using the '.*' form of import should be avoided - javax.swing.WindowConstants.*.", - "26: Using the '.*' form of import should be avoided - javax.swing.WindowConstants.*.", - "28: Using the '.*' form of import should be avoided - java.io.File.*.", + "7: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.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("imports" + File.separator + "InputAvoidStarImportCheck.java"), @@ -55,8 +57,8 @@ public class AvoidStarImportTest "java.io,java.lang,javax.swing.WindowConstants.*, javax.swing.WindowConstants"); // allow the java.io/java.lang,javax.swing.WindowConstants star imports final String[] expected2 = new String[] { - "7: Using the '.*' form of import should be avoided - com.puppycrawl.tools.checkstyle.imports.*.", - "28: Using the '.*' form of import should be avoided - java.io.File.*.", + "7: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.imports.*"), + "28: " + getCheckMessage(MSG_KEY, "java.io.File.*"), }; verify(checkConfig, getPath("imports" + File.separator + "InputAvoidStarImportCheck.java"), expected2); @@ -69,9 +71,9 @@ public class AvoidStarImportTest checkConfig.addAttribute("allowClassImports", "true"); // allow all class star imports final String[] expected2 = new String[] { - "25: Using the '.*' form of import should be avoided - javax.swing.WindowConstants.*.", - "26: Using the '.*' form of import should be avoided - javax.swing.WindowConstants.*.", - "28: Using the '.*' form of import should be avoided - java.io.File.*.", }; + "25: " + getCheckMessage(MSG_KEY, "javax.swing.WindowConstants.*"), + "26: " + getCheckMessage(MSG_KEY, "javax.swing.WindowConstants.*"), + "28: " + getCheckMessage(MSG_KEY, "java.io.File.*"), }; verify(checkConfig, getPath("imports" + File.separator + "InputAvoidStarImportCheck.java"), expected2); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStaticImportTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStaticImportTest.java index 1288d8d98..a4bba5056 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStaticImportTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/AvoidStaticImportTest.java @@ -23,6 +23,8 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import java.io.File; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.imports.AvoidStaticImportCheck.MSG_KEY; + public class AvoidStaticImportTest extends BaseCheckTestSupport { @@ -33,11 +35,11 @@ public class AvoidStaticImportTest final DefaultConfiguration checkConfig = createCheckConfig(AvoidStaticImportCheck.class); final String[] expected = { - "23: Using a static member import should be avoided - java.io.File.listRoots.", - "25: Using a static member import should be avoided - javax.swing.WindowConstants.*.", - "26: Using a static member import should be avoided - javax.swing.WindowConstants.*.", - "27: Using a static member import should be avoided - java.io.File.createTempFile.", - "28: Using a static member import should be avoided - java.io.File.pathSeparator.", + "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"), }; verify(checkConfig, getPath("imports" + File.separator + "InputAvoidStaticImportCheck.java"), expected); @@ -52,8 +54,8 @@ public class AvoidStaticImportTest checkConfig.addAttribute("excludes", "java.io.File.*,sun.net.ftpclient.FtpClient.*"); // allow the java.io.File.*/sun.net.ftpclient.FtpClient.* star imports final String[] expected = { - "25: Using a static member import should be avoided - javax.swing.WindowConstants.*.", - "26: Using a static member import should be avoided - javax.swing.WindowConstants.*.", + "25: " + getCheckMessage(MSG_KEY, "javax.swing.WindowConstants.*"), + "26: " + getCheckMessage(MSG_KEY, "javax.swing.WindowConstants.*"), }; verify(checkConfig, getPath("imports" + File.separator + "InputAvoidStaticImportCheck.java"), expected); } @@ -67,10 +69,10 @@ public class AvoidStaticImportTest checkConfig.addAttribute("excludes", "java.io.File.listRoots"); // allow the java.io.File.listRoots member imports final String[] expected = { - "25: Using a static member import should be avoided - javax.swing.WindowConstants.*.", - "26: Using a static member import should be avoided - javax.swing.WindowConstants.*.", - "27: Using a static member import should be avoided - java.io.File.createTempFile.", - "28: Using a static member import should be avoided - java.io.File.pathSeparator.", + "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"), }; verify(checkConfig, getPath("imports" + File.separator + "InputAvoidStaticImportCheck.java"), expected); } @@ -87,11 +89,11 @@ public class AvoidStaticImportTest + "sun.net.ftpclient.FtpClient.*FtpClient, sun.net.ftpclient.FtpClientjunk, java.io.File.listRootsmorejunk"); // allow the java.io.File.listRoots member imports final String[] expected = { - "23: Using a static member import should be avoided - java.io.File.listRoots.", - "25: Using a static member import should be avoided - javax.swing.WindowConstants.*.", - "26: Using a static member import should be avoided - javax.swing.WindowConstants.*.", - "27: Using a static member import should be avoided - java.io.File.createTempFile.", - "28: Using a static member import should be avoided - java.io.File.pathSeparator.", + "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"), }; verify(checkConfig, getPath("imports" + File.separator + "InputAvoidStaticImportCheck.java"), expected); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/CustomImportOrderCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/CustomImportOrderCheckTest.java index e45962263..25a2757d4 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/CustomImportOrderCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/CustomImportOrderCheckTest.java @@ -23,6 +23,11 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import java.io.File; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck.MSG_LEX; +import static com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck.MSG_LINE_SEPARATOR; +import static com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck.MSG_NONGROUP_IMPORT; +import static com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck.MSG_ORDER; + public class CustomImportOrderCheckTest extends BaseCheckTestSupport { /** @@ -40,17 +45,17 @@ public class CustomImportOrderCheckTest extends BaseCheckTestSupport "STATIC###SAME_PACKAGE(3)###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE"); checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true"); final String[] expected = { - "4: Wrong lexicographical order for 'java.awt.Button.ABORT' import.", - "7: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "8: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "9: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "10: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "11: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "12: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "13: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "14: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "15: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "16: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", + "4: " + getCheckMessage(MSG_LEX, "java.awt.Button.ABORT"), + "7: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "8: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "9: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "10: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "11: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "12: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "13: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "14: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "15: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "16: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), }; verify(checkConfig, getPath("imports" + File.separator @@ -72,11 +77,11 @@ public class CustomImportOrderCheckTest extends BaseCheckTestSupport "STATIC###STANDARD_JAVA_PACKAGE###THIRD_PARTY_PACKAGE"); checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true"); final String[] expected = { - "4: Wrong lexicographical order for 'java.awt.Button.ABORT' import.", - "9: Wrong lexicographical order for 'java.awt.Dialog' import.", - "13: Wrong lexicographical order for 'java.io.File' import.", - "15: Wrong lexicographical order for 'java.io.InputStream' import.", - "20: Wrong lexicographical order for 'com.google.common.*' import.", + "4: " + getCheckMessage(MSG_LEX, "java.awt.Button.ABORT"), + "9: " + getCheckMessage(MSG_LEX, "java.awt.Dialog"), + "13: " + getCheckMessage(MSG_LEX, "java.io.File"), + "15: " + getCheckMessage(MSG_LEX, "java.io.InputStream"), + "20: " + getCheckMessage(MSG_LEX, "com.google.common.*"), }; verify(checkConfig, getPath("imports" + File.separator @@ -98,13 +103,13 @@ public class CustomImportOrderCheckTest extends BaseCheckTestSupport "STATIC###STANDARD_JAVA_PACKAGE###THIRD_PARTY_PACKAGE###SAME_PACKAGE(3)"); checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true"); final String[] expected = { - "4: Wrong lexicographical order for 'java.awt.Button.ABORT' import.", - "9: Wrong lexicographical order for 'java.awt.Dialog' import.", - "13: Wrong lexicographical order for 'java.io.File' import.", - "15: Wrong lexicographical order for 'java.io.InputStream' import.", - "18: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", - "20: Imports without groups should be placed at the end of the import list.", - "21: 'org.junit.*'should be separated from previous import group.", + "4: " + getCheckMessage(MSG_LEX, "java.awt.Button.ABORT"), + "9: " + getCheckMessage(MSG_LEX, "java.awt.Dialog"), + "13: " + getCheckMessage(MSG_LEX, "java.io.File"), + "15: " + getCheckMessage(MSG_LEX, "java.io.InputStream"), + "18: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), + "20: " + getCheckMessage(MSG_NONGROUP_IMPORT), + "21: " + getCheckMessage(MSG_LINE_SEPARATOR, "org.junit.*"), }; verify(checkConfig, getPath("imports" + File.separator @@ -121,11 +126,11 @@ public class CustomImportOrderCheckTest extends BaseCheckTestSupport "STANDARD_JAVA_PACKAGE"); checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true"); final String[] expected = { - "7: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "8: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "9: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "10: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "11: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", + "7: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "8: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "9: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "10: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "11: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), }; verify(checkConfig, getPath("imports" + File.separator @@ -142,13 +147,13 @@ public class CustomImportOrderCheckTest extends BaseCheckTestSupport "STATIC###SAME_PACKAGE(3)"); checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true"); final String[] expected = { - "4: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", - "5: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", - "6: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", - "7: Import statement is in the wrong order. Should be in the 'STATIC' group.", - "8: Import statement is in the wrong order. Should be in the 'STATIC' group.", - "10: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", - "11: Import statement is in the wrong order. Should be in the 'STATIC' group.", + "4: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), + "5: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), + "6: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), + "7: " + getCheckMessage(MSG_ORDER, "STATIC"), + "8: " + getCheckMessage(MSG_ORDER, "STATIC"), + "10: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), + "11: " + getCheckMessage(MSG_ORDER, "STATIC"), }; verify(checkConfig, new File("src/test/resources-noncompilable/com/puppycrawl/tools/" @@ -164,11 +169,11 @@ public class CustomImportOrderCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("customImportOrderRules", "SAME_PACKAGE(3)"); checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true"); final String[] expected = { - "4: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", - "6: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", - "7: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", - "8: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", - "9: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", + "4: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), + "6: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), + "7: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), + "8: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), + "9: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), }; verify(checkConfig, new File("src/test/resources-noncompilable/com/puppycrawl/tools/" @@ -187,13 +192,13 @@ public class CustomImportOrderCheckTest extends BaseCheckTestSupport "STATIC###SAME_PACKAGE(3)"); checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true"); final String[] expected = { - "4: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", - "5: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", - "6: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", - "7: Import statement is in the wrong order. Should be in the 'STATIC' group.", - "8: Import statement is in the wrong order. Should be in the 'STATIC' group.", - "10: Import statement is in the wrong order. Should be in the 'SAME_PACKAGE' group.", - "11: Import statement is in the wrong order. Should be in the 'STATIC' group.", + "4: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), + "5: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), + "6: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), + "7: " + getCheckMessage(MSG_ORDER, "STATIC"), + "8: " + getCheckMessage(MSG_ORDER, "STATIC"), + "10: " + getCheckMessage(MSG_ORDER, "SAME_PACKAGE"), + "11: " + getCheckMessage(MSG_ORDER, "STATIC"), }; verify(checkConfig, new File("src/test/resources-noncompilable/com/puppycrawl/tools/" @@ -228,7 +233,7 @@ public class CustomImportOrderCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("customImportOrderRules", "STATIC###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE"); final String[] expected = { - "5: Import statement is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group.", + "5: " + getCheckMessage(MSG_ORDER, "THIRD_PARTY_PACKAGE"), }; verify(checkConfig, getPath("imports" + File.separator @@ -250,18 +255,18 @@ public class CustomImportOrderCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("sortImportsInGroupAlphabetically", "true"); final String[] expected = { - "7: Wrong lexicographical order for 'java.awt.Button.ABORT' import.", - "10: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "11: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "12: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "13: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "14: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "15: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "16: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "17: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "18: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "19: Import statement is in the wrong order. Should be in the 'STANDARD_JAVA_PACKAGE' group.", - "23: Wrong lexicographical order for 'com.google.common.*' import.", + "7: " + getCheckMessage(MSG_LEX, "java.awt.Button.ABORT"), + "10: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "11: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "12: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "13: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "14: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "15: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "16: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "17: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "18: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "19: " + getCheckMessage(MSG_ORDER, "STANDARD_JAVA_PACKAGE"), + "23: " + getCheckMessage(MSG_LEX, "com.google.common.*"), }; verify(checkConfig, new File("src/test/resources-noncompilable/com/puppycrawl/tools/" @@ -295,7 +300,7 @@ public class CustomImportOrderCheckTest extends BaseCheckTestSupport "SAME_PACKAGE(3)###THIRD_PARTY_PACKAGE###STATIC###" + "SPECIAL_IMPORTS"); final String[] expected = { - "11: Import statement is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group.", + "11: " + getCheckMessage(MSG_ORDER, "THIRD_PARTY_PACKAGE"), }; verify(checkConfig, getPath("imports" + File.separator diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheckTest.java index 42b975754..15ee8143c 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheckTest.java @@ -23,6 +23,8 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import java.io.File; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck.MSG_KEY; + public class IllegalImportCheckTest extends BaseCheckTestSupport { @Test @@ -33,9 +35,9 @@ public class IllegalImportCheckTest extends BaseCheckTestSupport createCheckConfig(IllegalImportCheck.class); checkConfig.addAttribute("illegalPkgs", "java.io"); final String[] expected = { - "9:1: Import from illegal package - java.io.*.", - "23:1: Import from illegal package - java.io.File.listRoots.", - "27:1: Import from illegal package - java.io.File.createTempFile.", + "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("imports" + File.separator + "InputIllegalImportCheck.java"), expected); @@ -48,8 +50,8 @@ public class IllegalImportCheckTest extends BaseCheckTestSupport final DefaultConfiguration checkConfig = createCheckConfig(IllegalImportCheck.class); final String[] expected = { - "15:1: Import from illegal package - sun.applet.*.", - "28:1: Import from illegal package - sun.*.", + "15:1: " + getCheckMessage(MSG_KEY, "sun.applet.*"), + "28:1: " + getCheckMessage(MSG_KEY, "sun.*"), }; verify(checkConfig, getPath("imports" + File.separator + "InputIllegalImportCheck.java"), expected); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheckRegExTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheckRegExTest.java index 7cc615f09..a0846b98a 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheckRegExTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheckRegExTest.java @@ -23,6 +23,8 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import java.io.File; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheck.MSG_DISALLOWED; + public class ImportControlCheckRegExTest extends BaseCheckTestSupport { @Test @@ -31,7 +33,7 @@ public class ImportControlCheckRegExTest extends BaseCheckTestSupport final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class); checkConfig.addAttribute("file", "src/test/resources/com/puppycrawl/tools/checkstyle/import-control_one-re.xml"); - final String[] expected = {"5:1: Disallowed import - java.io.File."}; + final String[] expected = {"5:1: " + getCheckMessage(MSG_DISALLOWED, "java.io.File")}; verify(checkConfig, getPath("imports" + File.separator + "InputImportControl.java"), expected); @@ -44,9 +46,9 @@ public class ImportControlCheckRegExTest extends BaseCheckTestSupport checkConfig.addAttribute("file", "src/test/resources/com/puppycrawl/tools/checkstyle/import-control_two-re.xml"); final String[] expected = { - "3:1: Disallowed import - java.awt.Image.", - "4:1: Disallowed import - javax.swing.border.*.", - "6:1: Disallowed import - java.awt.Button.ABORT.", + "3:1: " + getCheckMessage(MSG_DISALLOWED, "java.awt.Image"), + "4:1: " + getCheckMessage(MSG_DISALLOWED, "javax.swing.border.*"), + "6:1: " + getCheckMessage(MSG_DISALLOWED, "java.awt.Button.ABORT"), }; verify(checkConfig, getPath("imports" + File.separator diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheckTest.java index 43b85d2f2..4ed194ec0 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportControlCheckTest.java @@ -19,12 +19,19 @@ package com.puppycrawl.tools.checkstyle.checks.imports; import static org.junit.Assert.fail; + import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import com.puppycrawl.tools.checkstyle.api.CheckstyleException; + import java.io.File; + import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheck.MSG_DISALLOWED; +import static com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheck.MSG_UNKNOWN_PKG; +import static com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheck.MSG_MISSING_FILE; + public class ImportControlCheckTest extends BaseCheckTestSupport { @Test @@ -32,7 +39,7 @@ public class ImportControlCheckTest extends BaseCheckTestSupport { final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class); checkConfig.addAttribute("file", "src/test/resources/com/puppycrawl/tools/checkstyle/import-control_one.xml"); - final String[] expected = {"5:1: Disallowed import - java.io.File."}; + final String[] expected = {"5:1: " + getCheckMessage(MSG_DISALLOWED, "java.io.File")}; verify(checkConfig, getPath("imports" + File.separator + "InputImportControl.java"), expected); @@ -45,9 +52,9 @@ public class ImportControlCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("file", "src/test/resources/com/puppycrawl/tools/checkstyle/import-control_two.xml"); final String[] expected = { - "3:1: Disallowed import - java.awt.Image.", - "4:1: Disallowed import - javax.swing.border.*.", - "6:1: Disallowed import - java.awt.Button.ABORT.", + "3:1: " + getCheckMessage(MSG_DISALLOWED, "java.awt.Image"), + "4:1: " + getCheckMessage(MSG_DISALLOWED, "javax.swing.border.*"), + "6:1: " + getCheckMessage(MSG_DISALLOWED, "java.awt.Button.ABORT"), }; verify(checkConfig, getPath("imports" + File.separator @@ -60,7 +67,7 @@ public class ImportControlCheckTest extends BaseCheckTestSupport final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class); checkConfig.addAttribute("file", "src/test/resources/com/puppycrawl/tools/checkstyle/import-control_wrong.xml"); - final String[] expected = {"1:40: Import control file does not handle this package."}; + final String[] expected = {"1:40: " + getCheckMessage(MSG_UNKNOWN_PKG)}; verify(checkConfig, getPath("imports" + File.separator + "InputImportControl.java"), expected); @@ -70,7 +77,7 @@ public class ImportControlCheckTest extends BaseCheckTestSupport public void testMissing() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class); - final String[] expected = {"1:40: Missing an import control file."}; + final String[] expected = {"1:40: " + getCheckMessage(MSG_MISSING_FILE)}; verify(checkConfig, getPath("imports" + File.separator + "InputImportControl.java"), expected); } @@ -80,7 +87,7 @@ public class ImportControlCheckTest extends BaseCheckTestSupport { final DefaultConfiguration checkConfig = createCheckConfig(ImportControlCheck.class); checkConfig.addAttribute("file", " "); - final String[] expected = {"1:40: Missing an import control file."}; + final String[] expected = {"1:40: " + getCheckMessage(MSG_MISSING_FILE)}; verify(checkConfig, getPath("imports" + File.separator + "InputImportControl.java"), expected); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheckTest.java index 67223c862..44cf7cfa6 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheckTest.java @@ -23,6 +23,9 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import java.io.File; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck.MSG_ORDERING; +import static com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck.MSG_SEPARATION; + public class ImportOrderCheckTest extends BaseCheckTestSupport { @Test @@ -31,10 +34,10 @@ public class ImportOrderCheckTest extends BaseCheckTestSupport final DefaultConfiguration checkConfig = createCheckConfig(ImportOrderCheck.class); final String[] expected = { - "5: Wrong order for 'java.awt.Dialog' import.", - "9: Wrong order for 'javax.swing.JComponent' import.", - "11: Wrong order for 'java.io.File' import.", - "13: Wrong order for 'java.io.IOException' import.", + "5: " + getCheckMessage(MSG_ORDERING, "java.awt.Dialog"), + "9: " + getCheckMessage(MSG_ORDERING, "javax.swing.JComponent"), + "11: " + getCheckMessage(MSG_ORDERING, "java.io.File"), + "13: " + getCheckMessage(MSG_ORDERING, "java.io.IOException"), }; verify(checkConfig, getPath("imports" + File.separator + "InputImportOrder.java"), expected); @@ -48,9 +51,9 @@ public class ImportOrderCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("groups", "javax.swing"); checkConfig.addAttribute("groups", "java.io"); final String[] expected = { - "5: Wrong order for 'java.awt.Dialog' import.", - "13: Wrong order for 'java.io.IOException' import.", - "16: Wrong order for 'javax.swing.WindowConstants.*' import.", + "5: " + getCheckMessage(MSG_ORDERING, "java.awt.Dialog"), + "13: " + getCheckMessage(MSG_ORDERING, "java.io.IOException"), + "16: " + getCheckMessage(MSG_ORDERING, "javax.swing.WindowConstants.*"), }; verify(checkConfig, getPath("imports" + File.separator + "InputImportOrder.java"), expected); @@ -63,7 +66,7 @@ public class ImportOrderCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("groups", "java, /^javax?\\.(awt|swing)\\./"); checkConfig.addAttribute("ordered", "false"); final String[] expected = { - "11: Wrong order for 'java.io.File' import.", + "11: " + getCheckMessage(MSG_ORDERING, "java.io.File"), }; verify(checkConfig, getPath("imports" + File.separator + "InputImportOrder.java"), expected); @@ -77,9 +80,9 @@ public class ImportOrderCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("separated", "true"); checkConfig.addAttribute("ordered", "false"); final String[] expected = { - "9: 'javax.swing.JComponent' should be separated from previous imports.", - "11: 'java.io.File' should be separated from previous imports.", - "16: Wrong order for 'javax.swing.WindowConstants.*' import.", + "9: " + getCheckMessage(MSG_SEPARATION, "javax.swing.JComponent"), + "11: " + getCheckMessage(MSG_SEPARATION, "java.io.File"), + "16: " + getCheckMessage(MSG_ORDERING, "javax.swing.WindowConstants.*"), }; verify(checkConfig, getPath("imports" + File.separator + "InputImportOrder.java"), expected); @@ -103,8 +106,8 @@ public class ImportOrderCheckTest extends BaseCheckTestSupport createCheckConfig(ImportOrderCheck.class); checkConfig.addAttribute("option", "top"); final String[] expected = { - "4: Wrong order for 'java.awt.Button.ABORT' import.", - "18: Wrong order for 'java.io.File.*' import.", + "4: " + getCheckMessage(MSG_ORDERING, "java.awt.Button.ABORT"), + "18: " + getCheckMessage(MSG_ORDERING, "java.io.File.*"), }; verify(checkConfig, getPath("imports" + File.separator + "InputImportOrder_Top.java"), expected); @@ -117,10 +120,10 @@ public class ImportOrderCheckTest extends BaseCheckTestSupport createCheckConfig(ImportOrderCheck.class); checkConfig.addAttribute("option", "above"); final String[] expected = { - "5: Wrong order for 'java.awt.Button.ABORT' import.", - "8: Wrong order for 'java.awt.Dialog' import.", - "13: Wrong order for 'java.io.File' import.", - "14: Wrong order for 'java.io.File.createTempFile' import.", + "5: " + getCheckMessage(MSG_ORDERING, "java.awt.Button.ABORT"), + "8: " + getCheckMessage(MSG_ORDERING, "java.awt.Dialog"), + "13: " + getCheckMessage(MSG_ORDERING, "java.io.File"), + "14: " + getCheckMessage(MSG_ORDERING, "java.io.File.createTempFile"), }; verify(checkConfig, getPath("imports" + File.separator + "InputImportOrder_Above.java"), expected); @@ -133,12 +136,13 @@ public class ImportOrderCheckTest extends BaseCheckTestSupport createCheckConfig(ImportOrderCheck.class); checkConfig.addAttribute("option", "inflow"); final String[] expected = { - "6: Wrong order for 'java.awt.Dialog' import.", - "11: Wrong order for 'javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE' import.", - "12: Wrong order for 'javax.swing.WindowConstants.*' import.", - "13: Wrong order for 'javax.swing.JTable' import.", - "15: Wrong order for 'java.io.File.createTempFile' import.", - "16: Wrong order for 'java.io.File' import.", + "6: " + getCheckMessage(MSG_ORDERING, "java.awt.Dialog"), + "11: " + getCheckMessage(MSG_ORDERING, + "javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE"), + "12: " + getCheckMessage(MSG_ORDERING, "javax.swing.WindowConstants.*"), + "13: " + getCheckMessage(MSG_ORDERING, "javax.swing.JTable"), + "15: " + getCheckMessage(MSG_ORDERING, "java.io.File.createTempFile"), + "16: " + getCheckMessage(MSG_ORDERING, "java.io.File"), }; verify(checkConfig, getPath("imports" + File.separator + "InputImportOrder_InFlow.java"), expected); @@ -153,8 +157,8 @@ public class ImportOrderCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("option", "under"); final String[] expected = { "5: Wrong order for 'java.awt.Dialog' import.", - "11: Wrong order for 'java.awt.Button.ABORT' import.", - "14: Wrong order for 'java.io.File' import.", + "11: " + getCheckMessage(MSG_ORDERING, "java.awt.Button.ABORT"), + "14: " + getCheckMessage(MSG_ORDERING, "java.io.File"), }; verify(checkConfig, getPath("imports" + File.separator + "InputImportOrder_Under.java"), expected); @@ -167,9 +171,9 @@ public class ImportOrderCheckTest extends BaseCheckTestSupport createCheckConfig(ImportOrderCheck.class); checkConfig.addAttribute("option", "bottom"); final String[] expected = { - "15: Wrong order for 'java.io.File' import.", - "18: Wrong order for 'java.awt.Button.ABORT' import.", - "21: Wrong order for 'java.io.Reader' import.", + "15: " + getCheckMessage(MSG_ORDERING, "java.io.File"), + "18: " + getCheckMessage(MSG_ORDERING, "java.awt.Button.ABORT"), + "21: " + getCheckMessage(MSG_ORDERING, "java.io.Reader"), }; verify(checkConfig, getPath("imports" + File.separator + "InputImportOrder_Bottom.java"), expected); @@ -182,7 +186,7 @@ public class ImportOrderCheckTest extends BaseCheckTestSupport createCheckConfig(ImportOrderCheck.class); checkConfig.addAttribute("tokens", "IMPORT"); final String[] expected = { - "6: Wrong order for 'java.awt.Button' import.", + "6: " + getCheckMessage(MSG_ORDERING, "java.awt.Button"), }; verify(checkConfig, getPath("imports" + File.separator + "InputImportOrder_HonorsTokensProperty.java"), expected); @@ -194,7 +198,7 @@ public class ImportOrderCheckTest extends BaseCheckTestSupport final DefaultConfiguration checkConfig = createCheckConfig(ImportOrderCheck.class); checkConfig.addAttribute("groups", "com,*,java"); final String[] expected = { - "9: Wrong order for 'javax.crypto.Cipher' import.", + "9: " + getCheckMessage(MSG_ORDERING, "javax.crypto.Cipher"), }; verify(checkConfig, getPath("imports" + File.separator + "InputImportOrder_Wildcard.java"), expected); diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheckTest.java index 18643329a..72ceab197 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheckTest.java @@ -23,6 +23,10 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import java.io.File; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.imports.RedundantImportCheck.MSG_DUPLICATE; +import static com.puppycrawl.tools.checkstyle.checks.imports.RedundantImportCheck.MSG_LANG; +import static com.puppycrawl.tools.checkstyle.checks.imports.RedundantImportCheck.MSG_SAME; + public class RedundantImportCheckTest extends BaseCheckTestSupport { @@ -33,12 +37,12 @@ public class RedundantImportCheckTest final DefaultConfiguration checkConfig = createCheckConfig(RedundantImportCheck.class); final String[] expected = { - "7:1: Redundant import from the same package - com.puppycrawl.tools.checkstyle.imports.*.", - "8:1: Redundant import from the same package - com.puppycrawl.tools.checkstyle.imports.InputImportBug.", - "10:1: Redundant import from the java.lang package - java.lang.*.", - "11:1: Redundant import from the java.lang package - java.lang.String.", - "14:1: Duplicate import to line 13 - java.util.List.", - "26:1: Duplicate import to line 25 - javax.swing.WindowConstants.*.", + "7:1: " + getCheckMessage(MSG_SAME, "com.puppycrawl.tools.checkstyle.imports.*"), + "8:1: " + getCheckMessage(MSG_SAME, "com.puppycrawl.tools.checkstyle.imports.InputImportBug"), + "10:1: " + getCheckMessage(MSG_LANG, "java.lang.*"), + "11:1: " + getCheckMessage(MSG_LANG, "java.lang.String"), + "14:1: " + getCheckMessage(MSG_DUPLICATE, 13, "java.util.List"), + "26:1: " + getCheckMessage(MSG_DUPLICATE, 25, "javax.swing.WindowConstants.*"), }; verify(checkConfig, getPath("imports" + File.separator + "InputRedundantImportCheck.java"), expected); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheckTest.java index d5396046b..105234af6 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/UnusedImportsCheckTest.java @@ -23,6 +23,8 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import java.io.File; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck.MSG_KEY; + public class UnusedImportsCheckTest extends BaseCheckTestSupport { @Test @@ -30,30 +32,30 @@ public class UnusedImportsCheckTest extends BaseCheckTestSupport { final DefaultConfiguration checkConfig = createCheckConfig(UnusedImportsCheck.class); final String[] expected = { - "8:45: Unused import - com.puppycrawl.tools.checkstyle.imports.InputImportBug.", - "11:8: Unused import - java.lang.String.", - "13:8: Unused import - java.util.List.", - "14:8: Unused import - java.util.List.", - "17:8: Unused import - java.util.Enumeration.", - "20:8: Unused import - javax.swing.JToggleButton.", - "22:8: Unused import - javax.swing.BorderFactory.", - "27:15: Unused import - java.io.File.createTempFile.", + "8:45: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.imports.InputImportBug"), + "11:8: " + getCheckMessage(MSG_KEY, "java.lang.String"), + "13:8: " + getCheckMessage(MSG_KEY, "java.util.List"), + "14:8: " + getCheckMessage(MSG_KEY, "java.util.List"), + "17:8: " + getCheckMessage(MSG_KEY, "java.util.Enumeration"), + "20:8: " + getCheckMessage(MSG_KEY, "javax.swing.JToggleButton"), + "22:8: " + getCheckMessage(MSG_KEY, "javax.swing.BorderFactory"), + "27:15: " + getCheckMessage(MSG_KEY, "java.io.File.createTempFile"), //"29:8: Unused import - java.awt.Component.", // Should be detected - "30:8: Unused import - java.awt.Graphics2D.", - "31:8: Unused import - java.awt.HeadlessException.", - "32:8: Unused import - java.awt.Label.", - "33:8: Unused import - java.util.Date.", - "34:8: Unused import - java.util.Calendar.", - "35:8: Unused import - java.util.BitSet.", - "37:8: Unused import - com.puppycrawl.tools.checkstyle.Checker.", - "38:8: Unused import - com.puppycrawl.tools.checkstyle.CheckerTest.", - "39:8: Unused import - com.puppycrawl.tools.checkstyle.BaseFileSetCheckTestSupport.", - "40:8: Unused import - com.puppycrawl.tools.checkstyle.Defn.", - "41:8: Unused import - com.puppycrawl.tools.checkstyle.Input15Extensions.", - "42:8: Unused import - com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest.", - "43:8: Unused import - com.puppycrawl.tools.checkstyle.CheckStyleTask.", - "44:8: Unused import - com.puppycrawl.tools.checkstyle.DefaultConfiguration.", - "45:8: Unused import - com.puppycrawl.tools.checkstyle.DefaultLogger.", + "30:8: " + getCheckMessage(MSG_KEY, "java.awt.Graphics2D"), + "31:8: " + getCheckMessage(MSG_KEY, "java.awt.HeadlessException"), + "32:8: " + getCheckMessage(MSG_KEY, "java.awt.Label"), + "33:8: " + getCheckMessage(MSG_KEY, "java.util.Date"), + "34:8: " + getCheckMessage(MSG_KEY, "java.util.Calendar"), + "35:8: " + getCheckMessage(MSG_KEY, "java.util.BitSet"), + "37:8: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.Checker"), + "38:8: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.CheckerTest"), + "39:8: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.BaseFileSetCheckTestSupport"), + "40:8: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.Defn"), + "41:8: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.Input15Extensions"), + "42:8: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest"), + "43:8: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.CheckStyleTask"), + "44:8: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.DefaultConfiguration"), + "45:8: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.DefaultLogger"), }; verify(checkConfig, getPath("imports" + File.separator + "InputUnusedImportsCheck.java"), expected); @@ -65,17 +67,17 @@ public class UnusedImportsCheckTest extends BaseCheckTestSupport final DefaultConfiguration checkConfig = createCheckConfig(UnusedImportsCheck.class); checkConfig.addAttribute("processJavadoc", "true"); final String[] expected = { - "8:45: Unused import - com.puppycrawl.tools.checkstyle.imports.InputImportBug.", - "11:8: Unused import - java.lang.String.", - "13:8: Unused import - java.util.List.", - "14:8: Unused import - java.util.List.", - "17:8: Unused import - java.util.Enumeration.", - "20:8: Unused import - javax.swing.JToggleButton.", - "22:8: Unused import - javax.swing.BorderFactory.", - "27:15: Unused import - java.io.File.createTempFile.", + "8:45: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.imports.InputImportBug"), + "11:8: " + getCheckMessage(MSG_KEY, "java.lang.String"), + "13:8: " + getCheckMessage(MSG_KEY, "java.util.List"), + "14:8: " + getCheckMessage(MSG_KEY, "java.util.List"), + "17:8: " + getCheckMessage(MSG_KEY, "java.util.Enumeration"), + "20:8: " + getCheckMessage(MSG_KEY, "javax.swing.JToggleButton"), + "22:8: " + getCheckMessage(MSG_KEY, "javax.swing.BorderFactory"), + "27:15: " + getCheckMessage(MSG_KEY, "java.io.File.createTempFile"), //"29:8: Unused import - java.awt.Component.", // Should be detected - "32:8: Unused import - java.awt.Label.", - "45:8: Unused import - com.puppycrawl.tools.checkstyle.DefaultLogger.", + "32:8: " + getCheckMessage(MSG_KEY, "java.awt.Label"), + "45:8: " + getCheckMessage(MSG_KEY, "com.puppycrawl.tools.checkstyle.DefaultLogger"), }; verify(checkConfig, getPath("imports" + File.separator + "InputUnusedImportsCheck.java"), expected);