use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.
the class SuppressWithNearbyCommentFilterTest method getTagsAfterExecution.
/**
* Calls the filter with a minimal set of inputs and returns a list of
* {@link SuppressWithNearbyCommentFilter} internal type {@code Tag}.
* Our goal is 100% test coverage, for this we use white-box testing.
* So we need access to the implementation details. For this reason,
* it is necessary to use reflection to gain access to the inner field here.
*
* @return {@code Tag} list
*/
private static List<?> getTagsAfterExecution(SuppressWithNearbyCommentFilter filter, String filename, String... lines) {
final FileContents contents = new FileContents(new FileText(new File(filename), Arrays.asList(lines)));
contents.reportSingleLineComment(1, 0);
final TreeWalkerAuditEvent dummyEvent = new TreeWalkerAuditEvent(contents, filename, new Violation(1, null, null, null, null, Object.class, null), null);
filter.accept(dummyEvent);
return TestUtil.getInternalState(filter, "tags");
}
use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.
the class SuppressionCommentFilterTest method getTagsAfterExecution.
/**
* Calls the filter with a minimal set of inputs and returns a list of
* {@link SuppressionCommentFilter} internal type {@code Tag}.
* Our goal is 100% test coverage, for this we use white-box testing.
* So we need access to the implementation details. For this reason,
* it is necessary to use reflection to gain access to the inner field here.
*
* @return {@code Tag} list
*/
private static List<Comparable<Object>> getTagsAfterExecution(SuppressionCommentFilter filter, String filename, String... lines) {
final FileContents contents = new FileContents(new FileText(new File(filename), Arrays.asList(lines)));
for (int lineNo = 0; lineNo < lines.length; lineNo++) {
final int colNo = lines[lineNo].indexOf("//");
if (colNo >= 0) {
contents.reportSingleLineComment(lineNo + 1, colNo);
}
}
final TreeWalkerAuditEvent dummyEvent = new TreeWalkerAuditEvent(contents, filename, new Violation(1, null, null, null, null, Object.class, ""), null);
filter.accept(dummyEvent);
return TestUtil.getInternalState(filter, "tags");
}
use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.
the class SuppressionXpathSingleFilterTest method testComplexQuery.
@Test
public void testComplexQuery() throws Exception {
final String xpath = "//VARIABLE_DEF[./IDENT[@text='pi'] and " + "../../IDENT[@text='countTokens']] " + "| //VARIABLE_DEF[./IDENT[@text='someVariable'] and ../../IDENT[@text='sum']]";
final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("InputSuppressionXpathSingleFilter", "Test", null, null, xpath);
final TreeWalkerAuditEvent eventOne = createEvent(5, 8, TokenTypes.VARIABLE_DEF);
final TreeWalkerAuditEvent eventTwo = createEvent(10, 4, TokenTypes.VARIABLE_DEF);
final TreeWalkerAuditEvent eventThree = createEvent(15, 8, TokenTypes.VARIABLE_DEF);
assertWithMessage("Event should be rejected").that(filter.accept(eventOne)).isFalse();
assertWithMessage("Event should be accepted").that(filter.accept(eventTwo)).isTrue();
assertWithMessage("Event should be rejected").that(filter.accept(eventThree)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.
the class SuppressionXpathSingleFilterTest method testNonMatchingFileNameModuleIdAndCheck.
@Test
public void testNonMatchingFileNameModuleIdAndCheck() throws Exception {
final String xpath = "NON_MATCHING_QUERY";
final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("InputSuppressionXpathSingleFilter", null, null, null, xpath);
final TreeWalkerAuditEvent ev = createEvent(3, 0, TokenTypes.CLASS_DEF);
assertWithMessage("Event should be accepted").that(filter.accept(ev)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.
the class SuppressionXpathSingleFilterTest method testNonMatchingTokenType.
@Test
public void testNonMatchingTokenType() throws Exception {
final String xpath = "//METHOD_DEF[@text='countTokens']";
final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("InputSuppressionXpathSingleFilter", "Test", null, null, xpath);
final TreeWalkerAuditEvent ev = createEvent(3, 0, TokenTypes.CLASS_DEF);
assertWithMessage("Event should be accepted").that(filter.accept(ev)).isTrue();
}
Aggregations