Search in sources :

Example 21 with TreeWalkerAuditEvent

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

the class XpathFilterElementTest method testNonMatchingFilePattern.

@Test
public void testNonMatchingFilePattern() throws Exception {
    final Pattern pattern = Pattern.compile("NonMatchingRegexp");
    final XpathFilterElement filter = new XpathFilterElement(pattern, null, null, null, null);
    final TreeWalkerAuditEvent ev = getEvent(3, 0, TokenTypes.CLASS_DEF);
    assertWithMessage("Event should be accepted").that(filter.accept(ev)).isTrue();
}
Also used : Pattern(java.util.regex.Pattern) TreeWalkerAuditEvent(com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent) Test(org.junit.jupiter.api.Test)

Example 22 with TreeWalkerAuditEvent

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

the class XpathFilterElementTest method testNonMatchingModuleId.

@Test
public void testNonMatchingModuleId() throws Exception {
    final XpathFilterElement filter = new XpathFilterElement("InputXpathFilterElementSuppressByXpath", "Test", null, "id19", null);
    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 23 with TreeWalkerAuditEvent

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

the class XpathQueryGeneratorTest method testConstructorWithTreeWalkerAuditEvent.

@Test
public void testConstructorWithTreeWalkerAuditEvent() {
    final Violation violation = new Violation(12, 1, "messages.properties", null, null, null, null, null, null);
    final TreeWalkerAuditEvent event = new TreeWalkerAuditEvent(new FileContents(fileText), "InputXpathQueryGenerator", violation, rootAst);
    final XpathQueryGenerator queryGenerator = new XpathQueryGenerator(event, DEFAULT_TAB_WIDTH);
    final List<String> actual = queryGenerator.generate();
    final List<String> expected = Arrays.asList("/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='InputXpathQueryGenerator']]", "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='InputXpathQueryGenerator']]/MODIFIERS", "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='InputXpathQueryGenerator']]/MODIFIERS" + "/LITERAL_PUBLIC");
    assertWithMessage("Generated queries do not match expected ones").that(actual).isEqualTo(expected);
}
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 24 with TreeWalkerAuditEvent

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

the class SuppressWithNearbyCommentFilterTest method testAcceptNullViolation.

@Test
public void testAcceptNullViolation() {
    final SuppressWithNearbyCommentFilter filter = new SuppressWithNearbyCommentFilter();
    final FileContents contents = new FileContents(new FileText(new File("filename"), Collections.singletonList("//SUPPRESS CHECKSTYLE ignore")));
    contents.reportSingleLineComment(1, 0);
    final TreeWalkerAuditEvent auditEvent = new TreeWalkerAuditEvent(contents, null, null, null);
    assertWithMessage("Filter should accept null violation").that(filter.accept(auditEvent)).isTrue();
}
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 25 with TreeWalkerAuditEvent

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

the class SuppressWithNearbyCommentFilterTest method testAcceptNullFileContents.

@Test
public void testAcceptNullFileContents() {
    final SuppressWithNearbyCommentFilter filter = new SuppressWithNearbyCommentFilter();
    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)

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