Search in sources :

Example 36 with AuditEvent

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

the class SuppressElementTest method testDecideByLine.

@Test
public void testDecideByLine() {
    final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
    //deny because there are matches on file name, check name, and line
    filter.setLines("1-10");
    assertFalse("In range 1-10", filter.accept(ev));
    filter.setLines("1-9, 11");
    assertTrue("Not in 1-9, 11", filter.accept(ev));
    filter.setLines(null);
    assertFalse("none", filter.accept(ev));
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Example 37 with AuditEvent

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

the class SuppressElementTest method testDecideByFileNameAndModuleMatchingModuleEqual.

@Test
public void testDecideByFileNameAndModuleMatchingModuleEqual() {
    final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, "MyModule", getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
    filter.setModuleId("MyModule");
    assertFalse(filter.accept(ev));
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Example 38 with AuditEvent

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

the class SuppressionCommentFilterTest method testAcceptNullLocalizedMessage.

@Test
public void testAcceptNullLocalizedMessage() {
    final SuppressionCommentFilter filter = new SuppressionCommentFilter();
    final AuditEvent auditEvent = new AuditEvent(this);
    Assert.assertTrue(filter.accept(auditEvent));
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.Test)

Example 39 with AuditEvent

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

the class SeverityMatchFilterTest method testAcceptOnMatch.

@Test
public void testAcceptOnMatch() {
    filter.setSeverity(SeverityLevel.INFO);
    filter.setAcceptOnMatch(false);
    final AuditEvent ev = new AuditEvent(this, "Test.java");
    // event with no message has severity level INFO
    assertFalse("no message", filter.accept(ev));
    final SeverityLevel errorLevel = SeverityLevel.ERROR;
    final LocalizedMessage errorMessage = new LocalizedMessage(0, 0, "", "", null, errorLevel, null, getClass(), null);
    final AuditEvent ev2 = new AuditEvent(this, "ATest.java", errorMessage);
    assertTrue("level:" + errorLevel, filter.accept(ev2));
    final SeverityLevel infoLevel = SeverityLevel.INFO;
    final LocalizedMessage infoMessage = new LocalizedMessage(0, 0, "", "", null, infoLevel, null, getClass(), null);
    final AuditEvent ev3 = new AuditEvent(this, "ATest.java", infoMessage);
    assertFalse("level:" + infoLevel, filter.accept(ev3));
}
Also used : SeverityLevel(com.puppycrawl.tools.checkstyle.api.SeverityLevel) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Example 40 with AuditEvent

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

the class SuppressElementTest method testDecideByFileNameAndModuleMatchingRegExpMatch.

@Test
public void testDecideByFileNameAndModuleMatchingRegExpMatch() {
    final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "TestSUFFIX", message);
    final SuppressElement filterWithoutChecks = new SuppressElement("Test");
    assertFalse(filterWithoutChecks.accept(ev));
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Aggregations

AuditEvent (com.puppycrawl.tools.checkstyle.api.AuditEvent)47 Test (org.junit.Test)38 LocalizedMessage (com.puppycrawl.tools.checkstyle.api.LocalizedMessage)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 SeverityLevel (com.puppycrawl.tools.checkstyle.api.SeverityLevel)4 ArrayList (java.util.ArrayList)4 AuditListener (com.puppycrawl.tools.checkstyle.api.AuditListener)3 Checker (com.puppycrawl.tools.checkstyle.Checker)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 Field (java.lang.reflect.Field)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 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 List (java.util.List)1 SinkEventAttributeSet (org.apache.maven.doxia.sink.SinkEventAttributeSet)1