Search in sources :

Example 31 with TreeWalkerAuditEvent

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

the class SuppressionXpathSingleFilterTest method testNoQuery.

@Test
public void testNoQuery() throws Exception {
    final TreeWalkerAuditEvent event = createEvent(15, 8, TokenTypes.VARIABLE_DEF);
    final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("InputSuppressionXpathSingleFilter", "Test", null, null, null);
    assertWithMessage("Event should be accepted").that(filter.accept(event)).isFalse();
}
Also used : TreeWalkerAuditEvent(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent) Test(org.junit.jupiter.api.Test)

Example 32 with TreeWalkerAuditEvent

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

the class SuppressionXpathSingleFilterTest method testNullFileName.

@Test
public void testNullFileName() {
    final String xpath = "NON_MATCHING_QUERY";
    final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("InputSuppressionXpathSingleFilter", "Test", null, null, xpath);
    final TreeWalkerAuditEvent ev = new TreeWalkerAuditEvent(null, null, 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)

Example 33 with TreeWalkerAuditEvent

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

the class SuppressionXpathSingleFilterTest method testNonMatchingModuleId.

@Test
public void testNonMatchingModuleId() throws Exception {
    final String xpath = "NON_MATCHING_QUERY";
    final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("InputSuppressionXpathSingleFilter", "Test", null, "id19", xpath);
    final Violation message = new Violation(3, 0, TokenTypes.CLASS_DEF, "", "", null, null, "id20", 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 34 with TreeWalkerAuditEvent

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

the class SuppressionXpathSingleFilterTest method testNullViolation.

@Test
public void testNullViolation() {
    final String xpath = "NON_MATCHING_QUERY";
    final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("InputSuppressionXpathSingleFilter", "Test", null, null, xpath);
    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)

Example 35 with TreeWalkerAuditEvent

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

the class SuppressionXpathSingleFilterTest method testMatching.

@Test
public void testMatching() throws Exception {
    final String xpath = "//CLASS_DEF[./IDENT" + "[@text='InputSuppressionXpathSingleFilter']]";
    final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("InputSuppressionXpathSingleFilter", "Test", null, null, xpath);
    final TreeWalkerAuditEvent ev = createEvent(3, 0, TokenTypes.CLASS_DEF);
    assertWithMessage("Event should be rejected").that(filter.accept(ev)).isFalse();
}
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