From 5ede09997c283b4c418f0f540848e006be04fa87 Mon Sep 17 00:00:00 2001 From: alexkravin Date: Fri, 20 Feb 2015 17:02:24 +0400 Subject: [PATCH] Refactored UTs, checks package, issue #537 --- .../checks/DescendantTokenCheck.java | 33 +++++++-- .../checks/FinalParametersCheck.java | 9 ++- .../checks/NewlineAtEndOfFileCheck.java | 17 ++++- .../tools/checkstyle/checks/RegexpCheck.java | 25 ++++++- .../checkstyle/checks/TodoCommentCheck.java | 9 ++- .../checks/TrailingCommentCheck.java | 9 ++- .../checkstyle/checks/TranslationCheck.java | 9 ++- .../checks/UncommentedMainCheck.java | 9 ++- .../checkstyle/checks/UpperEllCheck.java | 9 ++- .../checks/DescendantTokenCheckTest.java | 22 +++--- .../checks/FinalParametersCheckTest.java | 70 ++++++++++--------- .../checks/NewlineAtEndOfFileCheckTest.java | 6 +- .../checkstyle/checks/RegexpCheckTest.java | 36 +++++----- .../checks/TodoCommentCheckTest.java | 10 +-- .../checks/TrailingCommentCheckTest.java | 24 ++++--- .../checks/TranslationCheckTest.java | 6 +- .../checks/UncommentedMainCheckTest.java | 12 ++-- .../checkstyle/checks/UpperEllCheckTest.java | 4 +- 18 files changed, 221 insertions(+), 98 deletions(-) diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheck.java index f5417b5b6..21bebfcd6 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheck.java @@ -164,6 +164,31 @@ import java.util.Set; */ public class DescendantTokenCheck extends Check { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY_MIN = "descendant.token.min"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY_MAX = "descendant.token.max"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY_SUM_MIN = "descendant.token.sum.min"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY_SUM_MAX = "descendant.token.sum.max"; + /** minimum depth */ private int minimumDepth; /** maximum depth */ @@ -210,14 +235,14 @@ public class DescendantTokenCheck extends Check } if (total < minimumNumber) { log(ast.getLineNo(), ast.getColumnNo(), - (null == minimumMessage) ? "descendant.token.sum.min" + (null == minimumMessage) ? MSG_KEY_SUM_MIN : minimumMessage, String.valueOf(total), String.valueOf(minimumNumber), name); } if (total > maximumNumber) { log(ast.getLineNo(), ast.getColumnNo(), - (null == maximumMessage) ? "descendant.token.sum.max" + (null == maximumMessage) ? MSG_KEY_SUM_MAX : maximumMessage, String.valueOf(total), String.valueOf(maximumNumber), @@ -231,7 +256,7 @@ public class DescendantTokenCheck extends Check final String descendantName = TokenTypes .getTokenName(element); log(ast.getLineNo(), ast.getColumnNo(), - (null == minimumMessage) ? "descendant.token.min" + (null == minimumMessage) ? MSG_KEY_MIN : minimumMessage, String.valueOf(tokenCount), String.valueOf(minimumNumber), @@ -242,7 +267,7 @@ public class DescendantTokenCheck extends Check final String descendantName = TokenTypes .getTokenName(element); log(ast.getLineNo(), ast.getColumnNo(), - (null == maximumMessage) ? "descendant.token.max" + (null == maximumMessage) ? MSG_KEY_MAX : maximumMessage, String.valueOf(tokenCount), String.valueOf(maximumNumber), diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheck.java index 05d281742..ca23f4746 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheck.java @@ -51,6 +51,13 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes; */ public class FinalParametersCheck extends Check { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY = "final.parameter"; + /** * Option to ignore primitive types as params. */ @@ -179,7 +186,7 @@ public class FinalParametersCheck extends Check final DetailAST paramName = param.findFirstToken(TokenTypes.IDENT); final DetailAST firstNode = CheckUtils.getFirstNode(param); log(firstNode.getLineNo(), firstNode.getColumnNo(), - "final.parameter", paramName.getText()); + MSG_KEY, paramName.getText()); } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheck.java index e825d187d..a0b362471 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheck.java @@ -58,6 +58,19 @@ import org.apache.commons.beanutils.ConversionException; public class NewlineAtEndOfFileCheck extends AbstractFileSetCheck { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY_UNABLE_OPEN = "unable.open"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY_NO_NEWLINE_EOF = "noNewlineAtEOF"; + /** the line separator to check against. */ private LineSeparatorOption lineSeparator = LineSeparatorOption.SYSTEM; @@ -69,11 +82,11 @@ public class NewlineAtEndOfFileCheck try { randomAccessFile = new RandomAccessFile(file, "r"); if (!endsWithNewline(randomAccessFile)) { - log(0, "noNewlineAtEOF", file.getPath()); + log(0, MSG_KEY_NO_NEWLINE_EOF, file.getPath()); } } catch (final IOException e) { - log(0, "unable.open", file.getPath()); + log(0, MSG_KEY_UNABLE_OPEN, file.getPath()); } finally { Utils.closeQuietly(randomAccessFile); diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/RegexpCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/RegexpCheck.java index 3c817575c..567914314 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/RegexpCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/RegexpCheck.java @@ -52,6 +52,25 @@ import java.util.regex.Pattern; */ public class RegexpCheck extends AbstractFormatCheck { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_ILLEGAL_REGEXP = "illegal.regexp"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_REQUIRED_REGEXP = "required.regexp"; + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_DUPLICATE_REGEXP = "duplicate.regexp"; + /** Default duplicate limit */ private static final int DEFAULT_DUPLICATE_LIMIT = -1; @@ -228,14 +247,14 @@ public class RegexpCheck extends AbstractFormatCheck msg = ERROR_LIMIT_EXCEEDED_MESSAGE + msg; } if (illegalPattern) { - log(lineNumber, "illegal.regexp", msg); + log(lineNumber, MSG_ILLEGAL_REGEXP, msg); } else { if (lineNumber > 0) { - log(lineNumber, "duplicate.regexp", msg); + log(lineNumber, MSG_DUPLICATE_REGEXP, msg); } else { - log(lineNumber, "required.regexp", msg); + log(lineNumber, MSG_REQUIRED_REGEXP, msg); } } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/TodoCommentCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/TodoCommentCheck.java index 8e999a47f..02fe29996 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/TodoCommentCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/TodoCommentCheck.java @@ -53,6 +53,13 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes; public class TodoCommentCheck extends Check { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY = "todo.match"; + /** * Format of todo comment. */ @@ -98,7 +105,7 @@ public class TodoCommentCheck for (int i = 0; i < lines.length; i++) { if (regexp.matcher(lines[i]).find()) { - log(ast.getLineNo() + i, "todo.match", format); + log(ast.getLineNo() + i, MSG_KEY, format); } } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheck.java index d83ba4a2b..91b26fc35 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheck.java @@ -99,6 +99,13 @@ import org.apache.commons.beanutils.ConversionException; */ public class TrailingCommentCheck extends AbstractFormatCheck { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY = "trailing.comments"; + /** default format for allowed blank line. */ private static final String DEFAULT_FORMAT = "^[\\s\\}\\);]*$"; @@ -178,7 +185,7 @@ public class TrailingCommentCheck extends AbstractFormatCheck && !blankLinePattern.matcher(lineBefore).find() && !isLegalComment(comment)) { - log(lineNo.intValue(), "trailing.comments"); + log(lineNo.intValue(), MSG_KEY); } } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java index 8ad486982..31b73b4ef 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheck.java @@ -70,6 +70,13 @@ import java.util.Map.Entry; public class TranslationCheck extends AbstractFileSetCheck { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY = "translation.missingKey"; + /** The property files to process. */ private final List propertyFiles = Lists.newArrayList(); @@ -251,7 +258,7 @@ public class TranslationCheck // Remaining elements in the key set are missing in the current file if (!keysClone.isEmpty()) { for (Object key : keysClone) { - log(0, "translation.missingKey", key); + log(0, MSG_KEY, key); } } fireErrors(path); diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheck.java index b6067660c..69bcc5a73 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheck.java @@ -44,6 +44,13 @@ import org.apache.commons.beanutils.ConversionException; public class UncommentedMainCheck extends Check { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY = "uncommented.main"; + /** the pattern to exclude classes from the check */ private String excludedClasses = "^$"; /** compiled regexp to exclude classes from check */ @@ -181,7 +188,7 @@ public class UncommentedMainCheck && checkType(method) && checkParams(method)) { - log(method.getLineNo(), "uncommented.main"); + log(method.getLineNo(), MSG_KEY); } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/UpperEllCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/UpperEllCheck.java index 19ce8b79e..fd866e50f 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/UpperEllCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/UpperEllCheck.java @@ -49,6 +49,13 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes; */ public class UpperEllCheck extends Check { + + /** + * A key is pointing to the warning message text in "messages.properties" + * file. + */ + public static final String MSG_KEY = "upperEll"; + @Override public int[] getDefaultTokens() { @@ -67,7 +74,7 @@ public class UpperEllCheck extends Check if (ast.getText().endsWith("l")) { log(ast.getLineNo(), ast.getColumnNo() + ast.getText().length() - 1, - "upperEll"); + MSG_KEY); } } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheckTest.java index 39e9804e9..de7b85f0e 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/DescendantTokenCheckTest.java @@ -18,10 +18,16 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle.checks; +import static com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.MSG_KEY_MAX; +import static com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.MSG_KEY_MIN; +import static com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck.MSG_KEY_SUM_MAX; + +import java.io.File; + +import org.junit.Test; + import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; import com.puppycrawl.tools.checkstyle.DefaultConfiguration; -import java.io.File; -import org.junit.Test; public class DescendantTokenCheckTest extends BaseCheckTestSupport { @@ -45,7 +51,7 @@ public class DescendantTokenCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("limitedTokens", "LITERAL_NATIVE"); checkConfig.addAttribute("maximumNumber", "0"); final String[] expected = { - "20:12: Count of 1 for 'LITERAL_NATIVE' descendant 'LITERAL_NATIVE' exceeds maximum count 0.", + "20:12: " + getCheckMessage(MSG_KEY_MAX, 1, 0, "LITERAL_NATIVE", "LITERAL_NATIVE"), }; verify(checkConfig, getPath("InputIllegalTokens.java"), expected); } @@ -76,7 +82,7 @@ public class DescendantTokenCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("limitedTokens", "LITERAL_DEFAULT"); checkConfig.addAttribute("minimumNumber", "2"); final String[] expected = { - "11:9: Count of 1 for 'LITERAL_SWITCH' descendant 'LITERAL_DEFAULT' is less than minimum count 2.", + "11:9: " + getCheckMessage(MSG_KEY_MIN, 1, 2, "LITERAL_SWITCH", "LITERAL_DEFAULT"), }; verify(checkConfig, getPath("InputIllegalTokens.java"), expected); } @@ -308,10 +314,10 @@ public class DescendantTokenCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("sumTokenCounts", "true"); String[] expected = { - "22:32: Total count of 2 exceeds maximum count 1 under 'EQUAL'.", - "22:50: Total count of 2 exceeds maximum count 1 under 'EQUAL'.", - "23:33: Total count of 2 exceeds maximum count 1 under 'NOT_EQUAL'.", - "23:51: Total count of 2 exceeds maximum count 1 under 'NOT_EQUAL'.", + "22:32: " + getCheckMessage(MSG_KEY_SUM_MAX, 2, 1, "EQUAL"), + "22:50: " + getCheckMessage(MSG_KEY_SUM_MAX, 2, 1, "EQUAL"), + "23:33: " + getCheckMessage(MSG_KEY_SUM_MAX, 2, 1, "NOT_EQUAL"), + "23:51: " + getCheckMessage(MSG_KEY_SUM_MAX, 2, 1, "NOT_EQUAL"), }; verify(checkConfig, diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheckTest.java index dd8149c47..667af3a1c 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/FinalParametersCheckTest.java @@ -22,6 +22,8 @@ import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.FinalParametersCheck.MSG_KEY; + public class FinalParametersCheckTest extends BaseCheckTestSupport { @Test @@ -30,17 +32,17 @@ public class FinalParametersCheckTest extends BaseCheckTestSupport final DefaultConfiguration checkConfig = createCheckConfig(FinalParametersCheck.class); final String[] expected = { - "23:26: Parameter s should be final.", - "38:26: Parameter i should be final.", - "43:26: Parameter s should be final.", - "53:17: Parameter s should be final.", - "69:17: Parameter s should be final.", - "75:17: Parameter s should be final.", - "90:45: Parameter e should be final.", - "93:36: Parameter e should be final.", - "110:18: Parameter aParam should be final.", - "113:18: Parameter args should be final.", - "116:18: Parameter args should be final.", + "23:26: " + getCheckMessage(MSG_KEY, "s"), + "38:26: " + getCheckMessage(MSG_KEY, "i"), + "43:26: " + getCheckMessage(MSG_KEY, "s"), + "53:17: " + getCheckMessage(MSG_KEY, "s"), + "69:17: " + getCheckMessage(MSG_KEY, "s"), + "75:17: " + getCheckMessage(MSG_KEY, "s"), + "90:45: " + getCheckMessage(MSG_KEY, "e"), + "93:36: " + getCheckMessage(MSG_KEY, "e"), + "110:18: " + getCheckMessage(MSG_KEY, "aParam"), + "113:18: " + getCheckMessage(MSG_KEY, "args"), + "116:18: " + getCheckMessage(MSG_KEY, "args"), }; verify(checkConfig, getPath("InputFinalParameters.java"), expected); } @@ -52,9 +54,9 @@ public class FinalParametersCheckTest extends BaseCheckTestSupport createCheckConfig(FinalParametersCheck.class); checkConfig.addAttribute("tokens", "CTOR_DEF"); final String[] expected = { - "23:26: Parameter s should be final.", - "38:26: Parameter i should be final.", - "43:26: Parameter s should be final.", + "23:26: " + getCheckMessage(MSG_KEY, "s"), + "38:26: " + getCheckMessage(MSG_KEY, "i"), + "43:26: " + getCheckMessage(MSG_KEY, "s"), }; verify(checkConfig, getPath("InputFinalParameters.java"), expected); } @@ -66,14 +68,14 @@ public class FinalParametersCheckTest extends BaseCheckTestSupport createCheckConfig(FinalParametersCheck.class); checkConfig.addAttribute("tokens", "METHOD_DEF"); final String[] expected = { - "53:17: Parameter s should be final.", - "69:17: Parameter s should be final.", - "75:17: Parameter s should be final.", - "90:45: Parameter e should be final.", - "93:36: Parameter e should be final.", - "110:18: Parameter aParam should be final.", - "113:18: Parameter args should be final.", - "116:18: Parameter args should be final.", + "53:17: " + getCheckMessage(MSG_KEY, "s"), + "69:17: " + getCheckMessage(MSG_KEY, "s"), + "75:17: " + getCheckMessage(MSG_KEY, "s"), + "90:45: " + getCheckMessage(MSG_KEY, "e"), + "93:36: " + getCheckMessage(MSG_KEY, "e"), + "110:18: " + getCheckMessage(MSG_KEY, "aParam"), + "113:18: " + getCheckMessage(MSG_KEY, "args"), + "116:18: " + getCheckMessage(MSG_KEY, "args"), }; verify(checkConfig, getPath("InputFinalParameters.java"), expected); } @@ -85,9 +87,9 @@ public class FinalParametersCheckTest extends BaseCheckTestSupport createCheckConfig(FinalParametersCheck.class); checkConfig.addAttribute("tokens", "LITERAL_CATCH"); final String[] expected = { - "125:16: Parameter npe should be final.", - "131:16: Parameter e should be final.", - "134:16: Parameter e should be final.", + "125:16: " + getCheckMessage(MSG_KEY, "npe"), + "131:16: " + getCheckMessage(MSG_KEY, "e"), + "134:16: " + getCheckMessage(MSG_KEY, "e"), }; verify(checkConfig, getPath("InputFinalParameters.java"), expected); } @@ -99,8 +101,8 @@ public class FinalParametersCheckTest extends BaseCheckTestSupport createCheckConfig(FinalParametersCheck.class); checkConfig.addAttribute("tokens", "FOR_EACH_CLAUSE"); final String[] expected = { - "150:13: Parameter s should be final.", - "158:13: Parameter s should be final.", + "150:13: " + getCheckMessage(MSG_KEY, "s"), + "158:13: " + getCheckMessage(MSG_KEY, "s"), }; verify(checkConfig, getPath("InputFinalParameters.java"), expected); } @@ -112,13 +114,13 @@ public class FinalParametersCheckTest extends BaseCheckTestSupport createCheckConfig(FinalParametersCheck.class); checkConfig.addAttribute("ignorePrimitiveTypes", "true"); final String[] expected = { - "6:22: Parameter k should be final.", - "7:15: Parameter s should be final.", - "7:25: Parameter o should be final.", - "8:15: Parameter array should be final.", - "9:31: Parameter s should be final.", - "10:22: Parameter l should be final.", - "10:32: Parameter s should be final.", + "6:22: " + getCheckMessage(MSG_KEY, "k"), + "7:15: " + getCheckMessage(MSG_KEY, "s"), + "7:25: " + getCheckMessage(MSG_KEY, "o"), + "8:15: " + getCheckMessage(MSG_KEY, "array"), + "9:31: " + getCheckMessage(MSG_KEY, "s"), + "10:22: " + getCheckMessage(MSG_KEY, "l"), + "10:32: " + getCheckMessage(MSG_KEY, "s"), }; verify(checkConfig, getPath("InputFinalParametersPrimitiveTypes.java"), expected); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheckTest.java index 1555ad93d..dbbfde0d1 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheckTest.java @@ -24,6 +24,8 @@ import com.puppycrawl.tools.checkstyle.api.CheckstyleException; import com.puppycrawl.tools.checkstyle.api.Configuration; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck.MSG_KEY_NO_NEWLINE_EOF; + public class NewlineAtEndOfFileCheckTest extends BaseCheckTestSupport { @@ -56,7 +58,7 @@ public class NewlineAtEndOfFileCheckTest createCheckConfig(NewlineAtEndOfFileCheck.class); checkConfig.addAttribute("lineSeparator", LineSeparatorOption.LF.toString()); final String[] expected = { - "0: File does not end with a newline.", + "0: " + getCheckMessage(MSG_KEY_NO_NEWLINE_EOF), }; verify( createChecker(checkConfig), @@ -81,7 +83,7 @@ public class NewlineAtEndOfFileCheckTest createCheckConfig(NewlineAtEndOfFileCheck.class); checkConfig.addAttribute("lineSeparator", LineSeparatorOption.LF.toString()); final String[] expected = { - "0: File does not end with a newline.", + "0: " + getCheckMessage(MSG_KEY_NO_NEWLINE_EOF), }; verify( createChecker(checkConfig), diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/RegexpCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/RegexpCheckTest.java index 533637455..4492fb466 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/RegexpCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/RegexpCheckTest.java @@ -22,6 +22,10 @@ import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.RegexpCheck.MSG_ILLEGAL_REGEXP; +import static com.puppycrawl.tools.checkstyle.checks.RegexpCheck.MSG_DUPLICATE_REGEXP; +import static com.puppycrawl.tools.checkstyle.checks.RegexpCheck.MSG_REQUIRED_REGEXP; + public class RegexpCheckTest extends BaseCheckTestSupport { @Test @@ -44,7 +48,7 @@ public class RegexpCheckTest extends BaseCheckTestSupport createCheckConfig(RegexpCheck.class); checkConfig.addAttribute("format", required); final String[] expected = { - "0: Required pattern '" + required + "' missing in file.", + "0: " + getCheckMessage(MSG_REQUIRED_REGEXP, required), }; verify(checkConfig, getPath("InputSemantic.java"), expected); } @@ -71,7 +75,7 @@ public class RegexpCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("format", required); checkConfig.addAttribute("duplicateLimit", "0"); final String[] expected = { - "24: Found duplicate pattern '" + required + "'.", + "24: " + getCheckMessage(MSG_DUPLICATE_REGEXP, required), }; verify(checkConfig, getPath("InputSemantic.java"), expected); } @@ -99,9 +103,9 @@ public class RegexpCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("illegalPattern", "true"); checkConfig.addAttribute("errorLimit", "4"); final String[] expected = { - "7: Line matches the illegal pattern '" + illegal + "'.", - "8: Line matches the illegal pattern '" + illegal + "'.", - "9: Line matches the illegal pattern '" + illegal + "'.", + "7: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegal), + "8: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegal), + "9: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegal), }; verify(checkConfig, getPath("InputSemantic.java"), expected); } @@ -118,9 +122,9 @@ public class RegexpCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("illegalPattern", "true"); checkConfig.addAttribute("errorLimit", "3"); final String[] expected = { - "7: Line matches the illegal pattern '" + illegal + "'.", - "8: Line matches the illegal pattern '" + illegal + "'.", - "9: Line matches the illegal pattern '" + error + illegal + "'.", + "7: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegal), + "8: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegal), + "9: " + getCheckMessage(MSG_ILLEGAL_REGEXP, error + illegal), }; verify(checkConfig, getPath("InputSemantic.java"), expected); } @@ -137,7 +141,7 @@ public class RegexpCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("illegalPattern", "true"); checkConfig.addAttribute("message", message); final String[] expected = { - "69: Line matches the illegal pattern '" + message + "'.", + "69: " + getCheckMessage(MSG_ILLEGAL_REGEXP, message), }; verify(checkConfig, getPath("InputSemantic.java"), expected); } @@ -153,7 +157,7 @@ public class RegexpCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("illegalPattern", "true"); checkConfig.addAttribute("message", null); final String[] expected = { - "69: Line matches the illegal pattern '" + illegal + "'.", + "69: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegal), }; verify(checkConfig, getPath("InputSemantic.java"), expected); } @@ -167,7 +171,7 @@ public class RegexpCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("format", illegal); checkConfig.addAttribute("illegalPattern", "true"); final String[] expected = { - "69: Line matches the illegal pattern '" + illegal + "'.", + "69: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegal), }; verify(checkConfig, getPath("InputSemantic.java"), expected); } @@ -181,7 +185,7 @@ public class RegexpCheckTest extends BaseCheckTestSupport checkConfigTrue.addAttribute("format", illegalTrue); checkConfigTrue.addAttribute("illegalPattern", "true"); final String[] expectedTrue = { - "69: Line matches the illegal pattern '" + illegalTrue + "'.", + "69: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegalTrue), }; verify(checkConfigTrue, getPath("InputSemantic.java"), expectedTrue); @@ -220,7 +224,7 @@ public class RegexpCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("illegalPattern", "true"); checkConfig.addAttribute("ignoreComments", "false"); final String[] expected = { - "4: Line matches the illegal pattern '" + illegal + "'.", + "4: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegal), }; verify(checkConfig, getPath("InputTrailingComment.java"), expected); } @@ -250,7 +254,7 @@ public class RegexpCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("illegalPattern", "true"); checkConfig.addAttribute("ignoreComments", "false"); final String[] expected = { - "19: Line matches the illegal pattern '" + illegal + "'.", + "19: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegal), }; verify(checkConfig, getPath("InputTrailingComment.java"), expected); } @@ -308,7 +312,7 @@ public class RegexpCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("illegalPattern", "true"); checkConfig.addAttribute("ignoreComments", "true"); final String[] expected = { - "22: Line matches the illegal pattern '" + illegal + "'.", + "22: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegal), }; verify(checkConfig, getPath("InputTrailingComment.java"), expected); } @@ -323,7 +327,7 @@ public class RegexpCheckTest extends BaseCheckTestSupport checkConfig.addAttribute("illegalPattern", "true"); checkConfig.addAttribute("ignoreComments", "true"); final String[] expected = { - "23: Line matches the illegal pattern '" + illegal + "'.", + "23: " + getCheckMessage(MSG_ILLEGAL_REGEXP, illegal), }; verify(checkConfig, getPath("InputTrailingComment.java"), expected); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TodoCommentCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TodoCommentCheckTest.java index b8b764b26..18aa6290f 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TodoCommentCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TodoCommentCheckTest.java @@ -22,6 +22,8 @@ import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck.MSG_KEY; + public class TodoCommentCheckTest extends BaseCheckTestSupport { @@ -32,10 +34,10 @@ public class TodoCommentCheckTest createCheckConfig(TodoCommentCheck.class); checkConfig.addAttribute("format", "FIXME:"); final String[] expected = { - "161: Comment matches to-do format 'FIXME:'.", - "162: Comment matches to-do format 'FIXME:'.", - "163: Comment matches to-do format 'FIXME:'.", - "167: Comment matches to-do format 'FIXME:'.", + "161: " + getCheckMessage(MSG_KEY, "FIXME:"), + "162: " + getCheckMessage(MSG_KEY, "FIXME:"), + "163: " + getCheckMessage(MSG_KEY, "FIXME:"), + "167: " + getCheckMessage(MSG_KEY, "FIXME:"), }; verify(checkConfig, getPath("InputSimple.java"), expected); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheckTest.java index b8642d7b8..58bf29748 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheckTest.java @@ -23,6 +23,8 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import org.junit.Before; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.TrailingCommentCheck.MSG_KEY; + public class TrailingCommentCheckTest extends BaseCheckTestSupport { private DefaultConfiguration checkConfig; @@ -37,12 +39,12 @@ public class TrailingCommentCheckTest extends BaseCheckTestSupport public void testDefaults() throws Exception { final String[] expected = { - "4: Don't use trailing comments.", - "7: Don't use trailing comments.", - "8: Don't use trailing comments.", - "18: Don't use trailing comments.", - "19: Don't use trailing comments.", - "29: Don't use trailing comments.", + "4: " + getCheckMessage(MSG_KEY), + "7: " + getCheckMessage(MSG_KEY), + "8: " + getCheckMessage(MSG_KEY), + "18: " + getCheckMessage(MSG_KEY), + "19: " + getCheckMessage(MSG_KEY), + "29: " + getCheckMessage(MSG_KEY), }; verify(checkConfig, getPath("InputTrailingComment.java"), expected); } @@ -52,11 +54,11 @@ public class TrailingCommentCheckTest extends BaseCheckTestSupport { checkConfig.addAttribute("legalComment", "^NOI18N$"); final String[] expected = { - "4: Don't use trailing comments.", - "7: Don't use trailing comments.", - "8: Don't use trailing comments.", - "18: Don't use trailing comments.", - "19: Don't use trailing comments.", + "4: " + getCheckMessage(MSG_KEY), + "7: " + getCheckMessage(MSG_KEY), + "8: " + getCheckMessage(MSG_KEY), + "18: " + getCheckMessage(MSG_KEY), + "19: " + getCheckMessage(MSG_KEY), }; verify(checkConfig, getPath("InputTrailingComment.java"), expected); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java index 085ebbf4e..5cf24c723 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TranslationCheckTest.java @@ -24,6 +24,8 @@ import com.puppycrawl.tools.checkstyle.api.Configuration; import java.io.File; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.TranslationCheck.MSG_KEY; + public class TranslationCheckTest extends BaseCheckTestSupport { @@ -41,7 +43,7 @@ public class TranslationCheckTest { final Configuration checkConfig = createCheckConfig(TranslationCheck.class); final String[] expected = { - "0: Key 'only.english' missing.", + "0: " + getCheckMessage(MSG_KEY, "only.english"), }; final File[] propertyFiles = new File[] { new File(getPath("messages_test_de.properties")), @@ -67,7 +69,7 @@ public class TranslationCheckTest final DefaultConfiguration checkConfig = createCheckConfig(TranslationCheck.class); checkConfig.addAttribute("basenameSeparator", "-"); final String[] expected = { - "0: Key 'only.english' missing.", + "0: " + getCheckMessage(MSG_KEY, "only.english"), }; final File[] propertyFiles = new File[] { new File(getPath("app-dev.properties")), diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheckTest.java index 3d6660f35..d04193ec4 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/UncommentedMainCheckTest.java @@ -22,6 +22,8 @@ import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.UncommentedMainCheck.MSG_KEY; + public class UncommentedMainCheckTest extends BaseCheckTestSupport { @@ -32,9 +34,9 @@ public class UncommentedMainCheckTest final DefaultConfiguration checkConfig = createCheckConfig(UncommentedMainCheck.class); final String[] expected = { - "14: Uncommented main method found.", - "23: Uncommented main method found.", - "32: Uncommented main method found.", + "14: " + getCheckMessage(MSG_KEY), + "23: " + getCheckMessage(MSG_KEY), + "32: " + getCheckMessage(MSG_KEY), }; verify(checkConfig, getPath("InputUncommentedMain.java"), expected); } @@ -47,8 +49,8 @@ public class UncommentedMainCheckTest createCheckConfig(UncommentedMainCheck.class); checkConfig.addAttribute("excludedClasses", "\\.Main.*$"); final String[] expected = { - "14: Uncommented main method found.", - "32: Uncommented main method found.", + "14: " + getCheckMessage(MSG_KEY), + "32: " + getCheckMessage(MSG_KEY), }; verify(checkConfig, getPath("InputUncommentedMain.java"), expected); } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/UpperEllCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/UpperEllCheckTest.java index 8ffae8394..67538ba66 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/UpperEllCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/UpperEllCheckTest.java @@ -22,6 +22,8 @@ import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; import com.puppycrawl.tools.checkstyle.DefaultConfiguration; import org.junit.Test; +import static com.puppycrawl.tools.checkstyle.checks.UpperEllCheck.MSG_KEY; + public class UpperEllCheckTest extends BaseCheckTestSupport { @@ -32,7 +34,7 @@ public class UpperEllCheckTest final DefaultConfiguration checkConfig = createCheckConfig(UpperEllCheck.class); final String[] expected = { - "94:43: Should use uppercase 'L'.", + "94:43: " + getCheckMessage(MSG_KEY), }; verify(checkConfig, getPath("InputSemantic.java"), expected); }