Search in sources :

Example 26 with TreeWalkerAuditEvent

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

the class SuppressionCommentFilterTest method testFindNearestMatchDontAllowSameColumn.

@Test
public void testFindNearestMatchDontAllowSameColumn() {
    final SuppressionCommentFilter suppressionCommentFilter = new SuppressionCommentFilter();
    final FileContents contents = new FileContents(new FileText(new File("filename"), Arrays.asList("//CHECKSTYLE:OFF: ConstantNameCheck", "line2")));
    contents.reportSingleLineComment(1, 0);
    final TreeWalkerAuditEvent dummyEvent = new TreeWalkerAuditEvent(contents, "filename", new Violation(1, null, null, null, null, Object.class, null), null);
    final boolean result = suppressionCommentFilter.accept(dummyEvent);
    assertWithMessage("Filter should not accept event").that(result).isFalse();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) FileContents(com.puppycrawl.tools.checkstyle.api.FileContents) TreeWalkerAuditEvent(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent) FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 27 with TreeWalkerAuditEvent

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

the class SuppressionCommentFilterTest method testAcceptNullViolation.

@Test
public void testAcceptNullViolation() {
    final SuppressionCommentFilter filter = new SuppressionCommentFilter();
    final FileContents contents = new FileContents(new FileText(new File("filename"), Arrays.asList("//CHECKSTYLE:OFF: ConstantNameCheck", "line2")));
    contents.reportSingleLineComment(1, 0);
    final TreeWalkerAuditEvent auditEvent = new TreeWalkerAuditEvent(contents, null, null, null);
    assertWithMessage("Filter should accept audit event").that(filter.accept(auditEvent)).isTrue();
    assertWithMessage("File name should not be null").that(auditEvent.getFileName()).isNull();
}
Also used : FileContents(com.puppycrawl.tools.checkstyle.api.FileContents) TreeWalkerAuditEvent(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent) FileText(com.puppycrawl.tools.checkstyle.api.FileText) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 28 with TreeWalkerAuditEvent

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

the class SuppressionCommentFilterTest method testAcceptNullFileContents.

@Test
public void testAcceptNullFileContents() {
    final SuppressionCommentFilter filter = new SuppressionCommentFilter();
    final FileContents contents = null;
    final TreeWalkerAuditEvent auditEvent = new TreeWalkerAuditEvent(contents, null, new Violation(1, null, null, null, null, Object.class, null), null);
    assertWithMessage("Filter should accept audit event").that(filter.accept(auditEvent)).isTrue();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) FileContents(com.puppycrawl.tools.checkstyle.api.FileContents) TreeWalkerAuditEvent(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent) Test(org.junit.jupiter.api.Test)

Example 29 with TreeWalkerAuditEvent

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

the class SuppressionXpathSingleFilterTest method testNonMatchingLineNumber.

@Test
public void testNonMatchingLineNumber() throws Exception {
    final String xpath = "//CLASS_DEF[@text='InputSuppressionXpathSingleFilter']";
    final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("InputSuppressionXpathSingleFilter", "Test", null, null, xpath);
    final TreeWalkerAuditEvent ev = createEvent(100, 0, 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 30 with TreeWalkerAuditEvent

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

the class SuppressionXpathSingleFilterTest method testNonMatchingFileRegexp.

@Test
public void testNonMatchingFileRegexp() throws Exception {
    final String xpath = "NON_MATCHING_QUERY";
    final SuppressionXpathSingleFilter filter = createSuppressionXpathSingleFilter("NonMatchingRegexp", "Test", null, null, xpath);
    final TreeWalkerAuditEvent ev = createEvent(3, 0, 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)

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