use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.
the class SuppressionXpathSingleFilterTest method testThrowException.
@Test
public void testThrowException() {
final String xpath = "//CLASS_DEF[@text='InputSuppressionXpathSingleFilter']";
final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("InputSuppressionXpathSingleFilter", "Test", null, null, xpath);
final Violation message = new Violation(3, 0, TokenTypes.CLASS_DEF, "", "", null, null, "id19", getClass(), null);
final TreeWalkerAuditEvent ev = new TreeWalkerAuditEvent(fileContents, file.getName(), message, null);
try {
filter.accept(ev);
assertWithMessage("Exception is expected").fail();
} catch (IllegalStateException ex) {
assertWithMessage("Exception message does not match expected one").that(ex.getMessage()).contains("Cannot initialize context and evaluate query");
}
}
use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.
the class SuppressionXpathSingleFilterTest method testNullModuleIdAndNonMatchingChecks.
@Test
public void testNullModuleIdAndNonMatchingChecks() throws Exception {
final String xpath = "NON_MATCHING_QUERY";
final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("InputSuppressionXpathSingleFilter", "NonMatchingRegexp", 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 testNonMatchingChecks.
@Test
public void testNonMatchingChecks() throws Exception {
final String xpath = "NON_MATCHING_QUERY";
final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("InputSuppressionXpathSingleFilter", "NonMatchingRegexp", null, "id19", xpath);
final Violation message = new Violation(3, 0, TokenTypes.CLASS_DEF, "", "", null, null, "id19", getClass(), null);
final TreeWalkerAuditEvent ev = new TreeWalkerAuditEvent(fileContents, file.getName(), message, JavaParser.parseFile(file, JavaParser.Options.WITHOUT_COMMENTS));
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 testDecideByMessage.
@Test
public void testDecideByMessage() throws Exception {
final Violation message = new Violation(0, 0, TokenTypes.CLASS_DEF, "", "", null, null, null, getClass(), "Test");
final TreeWalkerAuditEvent ev = new TreeWalkerAuditEvent(fileContents, file.getName(), message, JavaParser.parseFile(file, JavaParser.Options.WITHOUT_COMMENTS));
final SuppressionXpathSingleFilter filter1 = createSuppressionXpathSingleFilter(null, null, "Test", null, null);
final SuppressionXpathSingleFilter filter2 = createSuppressionXpathSingleFilter(null, null, "Bad", null, null);
assertWithMessage("Message match").that(filter1.accept(ev)).isFalse();
assertWithMessage("Message not match").that(filter2.accept(ev)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.
the class SuppressionXpathFilterTest method testAcceptOnNullFile.
@Test
public void testAcceptOnNullFile() throws Exception {
final String fileName = null;
final boolean optional = false;
final SuppressionXpathFilter filter = createSuppressionXpathFilter(fileName, optional);
final TreeWalkerAuditEvent ev = new TreeWalkerAuditEvent(null, "AnyJava.java", null, null);
assertWithMessage("TreeWalker audit event on null file should be accepted, but was not").that(filter.accept(ev)).isTrue();
}
Aggregations