Search in sources :

Example 71 with AuditEvent

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

the class SuppressElementTest method testDecideByFileNameAndModuleMatchingMessageNull.

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

Example 72 with AuditEvent

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

the class SuppressElementTest method testDecideByFileNameAndModuleMatchingCheckRegExpMatch.

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

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

the class SuppressElementTest method testDecideLocalizedMessage.

@Test
public void testDecideLocalizedMessage() {
    final LocalizedMessage message = new LocalizedMessage(0, 0, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
    //deny because there are matches on file and check names
    assertFalse("Names match", filter.accept(ev));
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Example 74 with AuditEvent

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

the class CheckStyleAuditListenerTest method testWithoutLocalizedMessage.

@Test
public void testWithoutLocalizedMessage() {
    final CheckStyleAuditListener underTest = new CheckStyleAuditListener(Collections.emptyMap(), false, 2, Optional.empty(), Collections.emptyList());
    try {
        // quite unlikely to happen in real life
        underTest.addError(new AuditEvent("source", "filename.java"));
        Assert.fail("expected exception was not thrown");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.Test)

Example 75 with AuditEvent

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

the class XMLLogger method writeFileMessages.

/**
 * Prints the file section with all file errors and exceptions.
 *
 * @param fileName The file name, as should be printed in the opening file tag.
 * @param messages The file messages.
 */
private void writeFileMessages(String fileName, FileMessages messages) {
    writeFileOpeningTag(fileName);
    if (messages != null) {
        for (AuditEvent errorEvent : messages.getErrors()) {
            writeFileError(errorEvent);
        }
        for (Throwable exception : messages.getExceptions()) {
            writeException(exception);
        }
    }
    writeFileClosingTag();
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent)

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