Refactored UTs, header package, issue #537

This commit is contained in:
alexkravin 2015-02-20 17:01:53 +04:00
parent 2ea1a3dbab
commit 5d698f4a58
2 changed files with 23 additions and 7 deletions

View File

@ -29,6 +29,19 @@ import java.util.List;
*/
public class HeaderCheck extends AbstractHeaderCheck
{
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_MISSING = "header.missing";
/**
* A key is pointing to the warning message text in "messages.properties"
* file.
*/
public static final String MSG_MISMATCH = "header.mismatch";
/** empty array to avoid instantiations. */
private static final int[] EMPTY_INT_ARRAY = new int[0];
@ -77,12 +90,12 @@ public class HeaderCheck extends AbstractHeaderCheck
protected void processFiltered(File file, List<String> lines)
{
if (getHeaderLines().size() > lines.size()) {
log(1, "header.missing");
log(1, MSG_MISSING);
}
else {
for (int i = 0; i < getHeaderLines().size(); i++) {
if (!isMatch(i, lines.get(i))) {
log(i + 1, "header.mismatch", getHeaderLines().get(i));
log(i + 1, MSG_MISMATCH, getHeaderLines().get(i));
break; // stop checking
}
}

View File

@ -29,6 +29,9 @@ import com.puppycrawl.tools.checkstyle.BaseFileSetCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import static com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck.MSG_MISMATCH;
import static com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck.MSG_MISSING;
public class HeaderCheckTest extends BaseFileSetCheckTestSupport
{
@Test
@ -39,7 +42,7 @@ public class HeaderCheckTest extends BaseFileSetCheckTestSupport
checkConfig.addAttribute("headerFile", getPath("configs/java.header"));
checkConfig.addAttribute("ignoreLines", "");
final String[] expected = {
"1: Missing a header - not enough lines in file.",
"1: " + getCheckMessage(MSG_MISSING),
};
verify(checkConfig, getPath("inputHeader.java"), expected);
}
@ -51,7 +54,7 @@ public class HeaderCheckTest extends BaseFileSetCheckTestSupport
createCheckConfig(RegexpHeaderCheck.class);
checkConfig.addAttribute("headerFile", getPath("regexp.header"));
final String[] expected = {
"3: Line does not match expected header line of '// Created: 2002'.",
"3: " + getCheckMessage(MSG_MISMATCH, "// Created: 2002"),
};
verify(checkConfig, getPath("InputScopeAnonInner.java"), expected);
}
@ -64,7 +67,7 @@ public class HeaderCheckTest extends BaseFileSetCheckTestSupport
URI uri = (new File(getPath("regexp.header"))).toURI();
checkConfig.addAttribute("headerFile", uri.toString());
final String[] expected = {
"3: Line does not match expected header line of '// Created: 2002'.",
"3: " + getCheckMessage(MSG_MISMATCH, "// Created: 2002"),
};
verify(checkConfig, getPath("InputScopeAnonInner.java"), expected);
}
@ -76,7 +79,7 @@ public class HeaderCheckTest extends BaseFileSetCheckTestSupport
createCheckConfig(RegexpHeaderCheck.class);
checkConfig.addAttribute("header", "^/*$\\n// .*\\n// Created: 2002\\n^//.*\\n^//.*");
final String[] expected = {
"3: Line does not match expected header line of '// Created: 2002'.",
"3: " + getCheckMessage(MSG_MISMATCH, "// Created: 2002"),
};
verify(checkConfig, getPath("InputScopeAnonInner.java"), expected);
}
@ -163,7 +166,7 @@ public class HeaderCheckTest extends BaseFileSetCheckTestSupport
checkConfig.addAttribute("headerFile", getPath("regexp.header2"));
checkConfig.addAttribute("multiLines", "3");
final String[] expected = {
"1: Missing a header - not enough lines in file.",
"1: " + getCheckMessage(MSG_MISSING),
};
verify(checkConfig, getPath("InputRegexpHeader4.java"), expected);
}