Search in sources :

Example 81 with AuditEvent

use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.

the class SuppressWarningsHolderTest method createAuditEvent.

private static AuditEvent createAuditEvent(String moduleId, int line, int column) {
    final Checker source = new Checker();
    final Violation violation = new Violation(line, column, null, null, null, moduleId, MemberNameCheck.class, "violation");
    return new AuditEvent(source, "filename", violation);
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) Checker(com.puppycrawl.tools.checkstyle.Checker) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent)

Example 82 with AuditEvent

use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.

the class SuppressWarningsHolderTest method testIsSuppressedByModuleId.

@Test
public void testIsSuppressedByModuleId() throws Exception {
    populateHolder("check", 100, 100, 350, 350);
    final AuditEvent event = createAuditEvent("check", 350, 350);
    assertWithMessage("Event is not suppressed").that(SuppressWarningsHolder.isSuppressed(event)).isTrue();
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 83 with AuditEvent

use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.

the class XpathFileGeneratorAstFilterTest method testNoXpathQuery.

@Test
public void testNoXpathQuery() throws Exception {
    final Violation violation = new Violation(10, 10, TokenTypes.LCURLY, "messages.properties", null, null, SeverityLevel.ERROR, null, LeftCurlyCheck.class, null);
    final TreeWalkerAuditEvent event = createTreeWalkerAuditEvent("InputXpathFileGeneratorAstFilter.java", violation);
    final XpathFileGeneratorAstFilter filter = new XpathFileGeneratorAstFilter();
    assertWithMessage("filter accepted").that(filter.accept(event)).isTrue();
    final AuditEvent auditEvent = new AuditEvent(this, getPath("InputXpathFileGeneratorAstFilter.java"), violation);
    assertWithMessage("expected null").that(XpathFileGeneratorAstFilter.findCorrespondingXpathQuery(auditEvent)).isNull();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 84 with AuditEvent

use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.

the class XpathFileGeneratorAstFilterTest method testAcceptNoToken.

@Test
public void testAcceptNoToken() {
    final Violation violation = new Violation(0, 0, 0, null, null, null, null, null, XpathFileGeneratorAstFilterTest.class, null);
    final TreeWalkerAuditEvent event = new TreeWalkerAuditEvent(null, null, violation, null);
    final XpathFileGeneratorAstFilter filter = new XpathFileGeneratorAstFilter();
    assertWithMessage("filter accepted").that(filter.accept(event)).isTrue();
    final AuditEvent auditEvent = new AuditEvent(this, "Test.java", violation);
    assertWithMessage("filter has no queries").that(XpathFileGeneratorAstFilter.findCorrespondingXpathQuery(auditEvent)).isNull();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 85 with AuditEvent

use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.

the class XpathFileGeneratorAstFilterTest method testTabWidth.

@Test
public void testTabWidth() throws Exception {
    final Violation violation = new Violation(6, 7, TokenTypes.LITERAL_RETURN, "messages.properties", null, null, SeverityLevel.ERROR, null, XpathFileGeneratorAstFilterTest.class, null);
    final TreeWalkerAuditEvent event = createTreeWalkerAuditEvent("InputXpathFileGeneratorAstFilter.java", violation);
    final XpathFileGeneratorAstFilter filter = new XpathFileGeneratorAstFilter();
    filter.setTabWidth(6);
    assertWithMessage("filter accepted").that(filter.accept(event)).isTrue();
    final AuditEvent auditEvent = new AuditEvent(this, getPath("InputXpathFileGeneratorAstFilter.java"), violation);
    assertWithMessage("expected xpath").that(XpathFileGeneratorAstFilter.findCorrespondingXpathQuery(auditEvent)).isEqualTo("/COMPILATION_UNIT" + "/CLASS_DEF[./IDENT[@text='InputXpathFileGeneratorAstFilter']]" + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='tabMethod']]/SLIST/LITERAL_RETURN");
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test)

Aggregations

AuditEvent (com.puppycrawl.tools.checkstyle.api.AuditEvent)110 Test (org.junit.jupiter.api.Test)76 Violation (com.puppycrawl.tools.checkstyle.api.Violation)51 Test (org.junit.Test)21 TreeWalkerTest (com.puppycrawl.tools.checkstyle.TreeWalkerTest)15 LocalizedMessage (com.puppycrawl.tools.checkstyle.api.LocalizedMessage)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 OutputStream (java.io.OutputStream)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 AuditListener (com.puppycrawl.tools.checkstyle.api.AuditListener)4 SeverityLevel (com.puppycrawl.tools.checkstyle.api.SeverityLevel)4 CloseAndFlushTestByteArrayOutputStream (com.puppycrawl.tools.checkstyle.internal.utils.CloseAndFlushTestByteArrayOutputStream)4 Method (java.lang.reflect.Method)3 Checker (com.puppycrawl.tools.checkstyle.Checker)2 ArrayList (java.util.ArrayList)2 CheckstyleCheckerListener (org.apache.maven.plugins.checkstyle.exec.CheckstyleCheckerListener)2 CheckstyleResults (org.apache.maven.plugins.checkstyle.exec.CheckstyleResults)2 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1