Skip to content

Commit

Permalink
Issue checkstyle#4365: Removed getConfigPath
Browse files Browse the repository at this point in the history
  • Loading branch information
djydewang committed Jul 11, 2017
1 parent fb8f131 commit 73a01b0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
Expand Up @@ -61,14 +61,10 @@ protected String getPath(String filename) throws IOException {
+ filename);
}

private String getConfigPath(String filename) throws IOException {
return super.getPath("configs" + File.separator + filename);
}

@Test
public void testStaticHeader() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
checkConfig.addAttribute("headerFile", getConfigPath("java.header"));
checkConfig.addAttribute("headerFile", getPath("inputheaderjava.header"));
checkConfig.addAttribute("ignoreLines", "");
final String[] expected = {
"1: " + getCheckMessage(MSG_MISSING),
Expand All @@ -82,7 +78,7 @@ public void testNoHeader() throws Exception {
try {
createChecker(checkConfig);
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRegexpHeader.java"), expected);
verify(checkConfig, getPath("InputHeaderRegexp.java"), expected);
}
catch (CheckstyleException ex) {
// Exception is not expected
Expand All @@ -97,7 +93,7 @@ public void testWhitespaceHeader() throws Exception {
try {
createChecker(checkConfig);
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputRegexpHeader.java"), expected);
verify(checkConfig, getPath("InputHeaderRegexp.java"), expected);
}
catch (CheckstyleException ex) {
// Exception is not expected
Expand Down Expand Up @@ -129,7 +125,7 @@ public void testNonExistingHeaderFile() throws Exception {
@Test
public void testInvalidCharset() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
checkConfig.addAttribute("headerFile", getConfigPath("java.header"));
checkConfig.addAttribute("headerFile", getPath("inputheaderjava.header"));
checkConfig.addAttribute("charset", "XSO-8859-1");
try {
createChecker(checkConfig);
Expand Down Expand Up @@ -181,22 +177,22 @@ public void testNullFilename() throws Exception {
@Test
public void testNotMatch() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
checkConfig.addAttribute("headerFile", getConfigPath("java.header"));
checkConfig.addAttribute("headerFile", getPath("inputheaderjava.header"));
checkConfig.addAttribute("ignoreLines", "");
final String[] expected = {
"2: " + getCheckMessage(MSG_MISMATCH,
"// checkstyle: Checks Java source code for adherence to a set of rules."),
};
verify(checkConfig, getConfigPath("java2.header"), expected);
verify(checkConfig, getPath("inputheaderjava2.header"), expected);
}

@Test
public void testIgnore() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
checkConfig.addAttribute("headerFile", getConfigPath("java.header"));
checkConfig.addAttribute("headerFile", getPath("inputheaderjava.header"));
checkConfig.addAttribute("ignoreLines", "2");
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getConfigPath("java2.header"), expected);
verify(checkConfig, getPath("inputheaderjava2.header"), expected);
}

@Test
Expand Down Expand Up @@ -235,7 +231,7 @@ public void testIoExceptionWhenLoadingHeaderFile() throws Exception {
PowerMockito.doThrow(new IOException("expected exception")).when(check, "loadHeader",
anyObject());

check.setHeaderFile(CommonUtils.getUriByFilename(getPath("InputRegexpHeader.java")));
check.setHeaderFile(CommonUtils.getUriByFilename(getPath("InputHeaderRegexp.java")));

final Method loadHeaderFile = AbstractHeaderCheck.class.getDeclaredMethod("loadHeaderFile");
loadHeaderFile.setAccessible(true);
Expand All @@ -253,7 +249,7 @@ public void testIoExceptionWhenLoadingHeaderFile() throws Exception {
@Test
public void testCacheHeaderFile() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
checkConfig.addAttribute("headerFile", getConfigPath("java.header"));
checkConfig.addAttribute("headerFile", getPath("inputheaderjava.header"));

final DefaultConfiguration checkerConfig = new DefaultConfiguration("checkstyle_checks");
checkerConfig.addChild(checkConfig);
Expand Down Expand Up @@ -298,9 +294,9 @@ public void testCacheHeaderWithoutFile() throws Exception {
@Test
public void testIgnoreLinesSorted() throws Exception {
final DefaultConfiguration checkConfig = createCheckConfig(HeaderCheck.class);
checkConfig.addAttribute("headerFile", getConfigPath("java.header"));
checkConfig.addAttribute("headerFile", getPath("inputheaderjava.header"));
checkConfig.addAttribute("ignoreLines", "4,2,3");
final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getConfigPath("java3.header"), expected);
verify(checkConfig, getPath("inputheaderjava3.header"), expected);
}
}
Expand Up @@ -6,6 +6,6 @@
* Some doc.
*/

public class InputRegexpHeader
public class InputHeaderRegexp
{
}

0 comments on commit 73a01b0

Please sign in to comment.