Search in sources :

Example 1 with AuditEvent

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

the class Checker method fireErrors.

/**
     * Notify all listeners about the errors in a file.
     *
     * @param fileName the audited file
     * @param errors the audit errors from the file
     */
@Override
public void fireErrors(String fileName, SortedSet<LocalizedMessage> errors) {
    final String stripped = CommonUtils.relativizeAndNormalizePath(basedir, fileName);
    boolean hasNonFilteredViolations = false;
    for (final LocalizedMessage element : errors) {
        final AuditEvent event = new AuditEvent(this, stripped, element);
        if (filters.accept(event)) {
            hasNonFilteredViolations = true;
            for (final AuditListener listener : listeners) {
                listener.addError(event);
            }
        }
    }
    if (hasNonFilteredViolations && cache != null) {
        cache.remove(fileName);
    }
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) AuditListener(com.puppycrawl.tools.checkstyle.api.AuditListener) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage)

Example 2 with AuditEvent

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

the class AuditEventDefaultFormatterTest method testFormatModuleNameContainsCheckSuffix.

@Test
public void testFormatModuleNameContainsCheckSuffix() {
    final AuditEvent mock = PowerMockito.mock(AuditEvent.class);
    when(mock.getSourceName()).thenReturn("TestModuleCheck");
    when(mock.getSeverityLevel()).thenReturn(SeverityLevel.WARNING);
    when(mock.getLine()).thenReturn(1);
    when(mock.getColumn()).thenReturn(1);
    when(mock.getMessage()).thenReturn("Mocked message.");
    when(mock.getFileName()).thenReturn("InputMockFile.java");
    final AuditEventFormatter formatter = new AuditEventDefaultFormatter();
    final String expected = "[WARN] InputMockFile.java:1:1: Mocked message. [TestModule]";
    assertEquals(expected, formatter.format(mock));
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with AuditEvent

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

the class SuppressElementTest method testDecideByFileNameAndModuleMatchingRegExpNotMatch.

@Test
public void testDecideByFileNameAndModuleMatchingRegExpNotMatch() {
    final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "T1est", 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 4 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 5 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)

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