Search in sources :

Example 11 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
    assertTrue("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);
    assertFalse("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);
    assertTrue("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 12 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");
    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 13 with AuditEvent

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

the class SuppressElementTest method testDecideByFileNameAndModuleMatchingModuleNull.

@Test
public void testDecideByFileNameAndModuleMatchingModuleNull() {
    final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, "MyModule", getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
    filter.setModuleId(null);
    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 14 with AuditEvent

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

the class SuppressElementTest method testDecideByFileNameAndModuleMatchingFileNameNull.

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

Example 15 with AuditEvent

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

the class SuppressWithNearbyCommentFilterTest method testAcceptNullLocalizedMessage.

@Test
public void testAcceptNullLocalizedMessage() {
    final SuppressWithNearbyCommentFilter filter = new SuppressWithNearbyCommentFilter();
    final AuditEvent auditEvent = new AuditEvent(this);
    Assert.assertTrue(filter.accept(auditEvent));
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) 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