Search in sources :

Example 51 with AuditEvent

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

the class SeverityMatchFilterTest method testSeverity.

@Test
public void testSeverity() {
    filter.setSeverity(SeverityLevel.INFO);
    final AuditEvent ev = new AuditEvent(this, "Test.java");
    // event with no message has severity level INFO
    assertWithMessage("no message").that(filter.accept(ev)).isTrue();
    final SeverityLevel errorLevel = SeverityLevel.ERROR;
    final Violation errorMessage = new Violation(1, 0, "", "", null, errorLevel, null, getClass(), null);
    final AuditEvent ev2 = new AuditEvent(this, "ATest.java", errorMessage);
    assertWithMessage("level:" + errorLevel).that(filter.accept(ev2)).isFalse();
    final SeverityLevel infoLevel = SeverityLevel.INFO;
    final Violation infoMessage = new Violation(1, 0, "", "", null, infoLevel, null, getClass(), null);
    final AuditEvent ev3 = new AuditEvent(this, "ATest.java", infoMessage);
    assertWithMessage("level:" + infoLevel).that(filter.accept(ev3)).isTrue();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) SeverityLevel(com.puppycrawl.tools.checkstyle.api.SeverityLevel) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 52 with AuditEvent

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

the class SeverityMatchFilterTest method testDefault.

@Test
public void testDefault() {
    final AuditEvent ev = new AuditEvent(this, "Test.java");
    assertWithMessage("no message").that(filter.accept(ev)).isFalse();
    final SeverityLevel errorLevel = SeverityLevel.ERROR;
    final Violation errorMessage = new Violation(1, 0, "", "", null, errorLevel, null, getClass(), null);
    final AuditEvent ev2 = new AuditEvent(this, "ATest.java", errorMessage);
    assertWithMessage("level:" + errorLevel).that(filter.accept(ev2)).isTrue();
    final SeverityLevel infoLevel = SeverityLevel.INFO;
    final Violation infoViolation = new Violation(1, 0, "", "", null, infoLevel, null, getClass(), null);
    final AuditEvent ev3 = new AuditEvent(this, "ATest.java", infoViolation);
    assertWithMessage("level:" + infoLevel).that(filter.accept(ev3)).isFalse();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) SeverityLevel(com.puppycrawl.tools.checkstyle.api.SeverityLevel) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 53 with AuditEvent

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

the class SuppressFilterElementTest method testDecideByLine.

@Test
public void testDecideByLine() {
    final Violation violation = new Violation(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", violation);
    final SuppressFilterElement filter1 = new SuppressFilterElement("Test", "Test", null, null, "1-10", null);
    final SuppressFilterElement filter2 = new SuppressFilterElement("Test", "Test", null, null, "1-9, 11", null);
    final SuppressFilterElement filter3 = new SuppressFilterElement("Test", "Test", null, null, null, null);
    // deny because there are matches on file name, check name, and line
    assertWithMessage("In range 1-10").that(filter1.accept(ev)).isFalse();
    assertWithMessage("Not in 1-9, 11").that(filter2.accept(ev)).isTrue();
    assertWithMessage("none").that(filter3.accept(ev)).isFalse();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test) TreeWalkerTest(com.puppycrawl.tools.checkstyle.TreeWalkerTest)

Example 54 with AuditEvent

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

the class SuppressFilterElementTest method testDecideByFileNameAndModuleMatchingCheckRegExpNotMatch.

@Test
public void testDecideByFileNameAndModuleMatchingCheckRegExpNotMatch() {
    final Violation message = new Violation(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
    final SuppressFilterElement myFilter = new SuppressFilterElement("Test", "NON_EXISTENT_CHECK", null, "MyModule", null, null);
    assertWithMessage("Filter should accept valid event").that(myFilter.accept(ev)).isTrue();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test) TreeWalkerTest(com.puppycrawl.tools.checkstyle.TreeWalkerTest)

Example 55 with AuditEvent

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

the class SuppressFilterElementTest method testDecideByMessage.

@Test
public void testDecideByMessage() {
    final Violation violation = new Violation(1, 0, "", "", null, null, getClass(), "Test");
    final AuditEvent ev = new AuditEvent(this, "ATest.java", violation);
    final SuppressFilterElement filter1 = new SuppressFilterElement(null, null, "Test", null, null, null);
    final SuppressFilterElement filter2 = new SuppressFilterElement(null, null, "Bad", null, null, null);
    assertWithMessage("Message match").that(filter1.accept(ev)).isFalse();
    assertWithMessage("Message not match").that(filter2.accept(ev)).isTrue();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test) TreeWalkerTest(com.puppycrawl.tools.checkstyle.TreeWalkerTest)

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