Refactored UTs, checks package, issue #537

This commit is contained in:
alexkravin 2015-02-20 17:02:24 +04:00
parent 27149f3504
commit 5ede09997c
18 changed files with 221 additions and 98 deletions

View File

@ -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),

View File

@ -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());
}
}

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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<File> 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);

View File

@ -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);
}
}

View File

@ -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);
}
}
}

View File

@ -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,

View File

@ -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);
}

View File

@ -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),

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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")),

View File

@ -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);
}

View File

@ -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);
}