Search in sources :

Example 11 with TreeWalkerAuditEvent

use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.

the class SuppressionXpathFilterTest method testNonExistentSuppressionFileWithTrueOptional.

@Test
public void testNonExistentSuppressionFileWithTrueOptional() throws Exception {
    final String fileName = "src/test/resources/com/puppycrawl/tools/checkstyle/filters/" + "non_existent_suppression_file.xml";
    final boolean optional = true;
    final SuppressionXpathFilter filter = createSuppressionXpathFilter(fileName, optional);
    final TreeWalkerAuditEvent ev = new TreeWalkerAuditEvent(null, "AnyFile.java", null, null);
    assertWithMessage("Should except event when suppression file does not exist").that(filter.accept(ev)).isTrue();
}
Also used : TreeWalkerAuditEvent(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent) Test(org.junit.jupiter.api.Test)

Example 12 with TreeWalkerAuditEvent

use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.

the class SuppressionXpathFilterTest method testReject.

@Test
public void testReject() throws Exception {
    final boolean optional = false;
    final SuppressionXpathFilter filter = createSuppressionXpathFilter(getPath("InputSuppressionXpathFilterIdAndQuery.xml"), optional);
    final File file = new File(getPath("InputSuppressionXpathFilter.java"));
    final Violation message = new Violation(3, 0, TokenTypes.CLASS_DEF, "", "", null, null, "777", getClass(), null);
    final TreeWalkerAuditEvent ev = new TreeWalkerAuditEvent(null, "file1.java", message, JavaParser.parseFile(file, JavaParser.Options.WITHOUT_COMMENTS));
    assertWithMessage("TreeWalker audit event should be rejected").that(filter.accept(ev)).isFalse();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) TreeWalkerAuditEvent(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 13 with TreeWalkerAuditEvent

use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.

the class SuppressionXpathSingleFilterTest method testNonMatchingColumnNumber.

@Test
public void testNonMatchingColumnNumber() throws Exception {
    final String xpath = "//CLASS_DEF[@text='InputSuppressionXpathSingleFilter']";
    final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("InputSuppressionXpathSingleFilter", "Test", null, null, xpath);
    final TreeWalkerAuditEvent ev = createEvent(3, 100, TokenTypes.CLASS_DEF);
    assertWithMessage("Event should be accepted").that(filter.accept(ev)).isTrue();
}
Also used : TreeWalkerAuditEvent(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent) Test(org.junit.jupiter.api.Test)

Example 14 with TreeWalkerAuditEvent

use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.

the class XpathFilterElementTest method testNonMatchingChecks.

@Test
public void testNonMatchingChecks() throws Exception {
    final String xpath = "NON_MATCHING_QUERY";
    final XpathFilterElement filter = new XpathFilterElement("InputXpathFilterElementSuppressByXpath", "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();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) TreeWalkerAuditEvent(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent) Test(org.junit.jupiter.api.Test)

Example 15 with TreeWalkerAuditEvent

use of com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent in project checkstyle by checkstyle.

the class XpathFilterElementTest method testNullViolation.

@Test
public void testNullViolation() {
    final XpathFilterElement filter = new XpathFilterElement("InputXpathFilterElementSuppressByXpath", "Test", null, null, null);
    final TreeWalkerAuditEvent ev = new TreeWalkerAuditEvent(null, file.getName(), null, null);
    assertWithMessage("Event should be accepted").that(filter.accept(ev)).isTrue();
}
Also used : TreeWalkerAuditEvent(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent) Test(org.junit.jupiter.api.Test)

Aggregations

TreeWalkerAuditEvent (com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent)49 Test (org.junit.jupiter.api.Test)47 Violation (com.puppycrawl.tools.checkstyle.api.Violation)17 FileContents (com.puppycrawl.tools.checkstyle.api.FileContents)8 File (java.io.File)6 FileText (com.puppycrawl.tools.checkstyle.api.FileText)5 Pattern (java.util.regex.Pattern)2