Skip to content

Commit

Permalink
Issue checkstyle#10548: Migrate to Inline Config Parser in MatchXpath…
Browse files Browse the repository at this point in the history
…CheckTest
  • Loading branch information
shashwatj07 committed Aug 19, 2021
1 parent 67675f2 commit 0b76ab1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
Expand Up @@ -44,7 +44,8 @@ public void testCheckWithEmptyQuery()
final DefaultConfiguration checkConfig =
createModuleConfig(MatchXpathCheck.class);
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputMatchXpath.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMatchXpath.java"), expected);
}

@Test
Expand All @@ -54,7 +55,8 @@ public void testNoStackoverflowError()
createModuleConfig(MatchXpathCheck.class);
checkConfig.addProperty("query", "//STRING_LITERAL[not(@text='')]");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputMatchXpathNoStackoverflowError.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMatchXpathNoStackoverflowError.java"), expected);
}

@Test
Expand All @@ -64,7 +66,8 @@ public void testCheckWithImplicitEmptyQuery()
createModuleConfig(MatchXpathCheck.class);
checkConfig.addProperty("query", "");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputMatchXpath2.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMatchXpath2.java"), expected);
}

@Test
Expand All @@ -77,7 +80,8 @@ public void testCheckWithMatchingMethodNames()
"11:5: " + getCheckMessage(MatchXpathCheck.MSG_KEY),
"13:5: " + getCheckMessage(MatchXpathCheck.MSG_KEY),
};
verify(checkConfig, getPath("InputMatchXpath3.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMatchXpath3.java"), expected);
}

@Test
Expand All @@ -88,7 +92,8 @@ public void testCheckWithNoMatchingMethodName()
checkConfig.addProperty("query", "//METHOD_DEF[./IDENT[@text='wrongName' or "
+ "@text='nonExistingMethod']]");
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("InputMatchXpath4.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMatchXpath4.java"), expected);
}

@Test
Expand All @@ -101,7 +106,8 @@ public void testCheckWithSingleLineCommentsStartsWithSpace() throws Exception {
"13:25: " + getCheckMessage(MatchXpathCheck.MSG_KEY),
"14:27: " + getCheckMessage(MatchXpathCheck.MSG_KEY),
};
verify(checkConfig, getPath("InputMatchXpathSingleLineComments.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMatchXpathSingleLineComments.java"), expected);
}

@Test
Expand All @@ -115,7 +121,8 @@ public void testCheckWithBlockComments() throws Exception {
"12:5: " + getCheckMessage(MatchXpathCheck.MSG_KEY),
"14:5: " + getCheckMessage(MatchXpathCheck.MSG_KEY),
};
verify(checkConfig, getPath("InputMatchXpathBlockComments.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMatchXpathBlockComments.java"), expected);
}

@Test
Expand All @@ -129,7 +136,8 @@ public void testCheckWithMultilineComments() throws Exception {
"14:5: " + getCheckMessage(MatchXpathCheck.MSG_KEY),
"20:5: " + getCheckMessage(MatchXpathCheck.MSG_KEY),
};
verify(checkConfig, getPath("InputMatchXpathMultilineComments.java"), expected);
verifyWithInlineConfigParser(checkConfig,
getPath("InputMatchXpathMultilineComments.java"), expected);
}

@Test
Expand Down Expand Up @@ -221,7 +229,7 @@ public void testAvoidInstanceCreationWithoutVar()
final String[] expected = {
"13:9: " + getCheckMessage(MatchXpathCheck.MSG_KEY),
};
verify(checkConfig,
verifyWithInlineConfigParser(checkConfig,
getNonCompilablePath("InputMatchXpathAvoidInstanceCreationWithoutVar.java"),
expected);
}
Expand Down
Expand Up @@ -8,9 +8,9 @@
package com.puppycrawl.tools.checkstyle.checks.coding.matchxpath;

public class InputMatchXpath {
public void test() { } // violation
public void test() { }

public void foo() { } // violation
public void foo() { }

public void correct() { } // ok
}
Expand Up @@ -8,9 +8,9 @@
package com.puppycrawl.tools.checkstyle.checks.coding.matchxpath;

public class InputMatchXpath2 {
public void test() { } // violation
public void test() { }

public void foo() { } // violation
public void foo() { }

public void correct() { } // ok
}
Expand Up @@ -8,9 +8,9 @@
package com.puppycrawl.tools.checkstyle.checks.coding.matchxpath;

public class InputMatchXpath4 {
public void test() { } // violation
public void test() { }

public void foo() { } // violation
public void foo() { }

public void correct() { } // ok
}
@@ -1,7 +1,7 @@
/*
MatchXpath
query = //BLOCK_COMMENT_BEGIN[./COMMENT_CONTENT[contains(@text, '{') \
and not(starts-with(@text, '\nMatchXpath'))]]
and not(starts-with(@text, '\\nMatchXpath'))]]
*/
Expand Down
@@ -1,7 +1,7 @@
/*
MatchXpath
query = //BLOCK_COMMENT_BEGIN[./COMMENT_CONTENT[contains(@text, '\n Forbidden comment\n') \
and not(starts-with(@text, '\nMatchXpath'))]]
query = //BLOCK_COMMENT_BEGIN[./COMMENT_CONTENT[contains(@text, '\\n Forbidden comment\\n') \
and not(starts-with(@text, '\\nMatchXpath'))]]
*/
Expand Down

0 comments on commit 0b76ab1

Please sign in to comment.