Search in sources :

Example 86 with AuditEvent

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

the class XMLLoggerTest method testAddErrorWithNullFileName.

@Test
public void testAddErrorWithNullFileName() throws Exception {
    final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
    logger.auditStarted(null);
    final Violation violation = new Violation(1, 1, "messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, null, violation);
    logger.addError(ev);
    logger.auditFinished(null);
    verifyXml(getPath("ExpectedXMLLoggerErrorNullFileName.xml"), outStream, violation.getViolation());
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 87 with AuditEvent

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

the class XMLLoggerTest method testAddError.

@Test
public void testAddError() throws Exception {
    final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
    logger.auditStarted(null);
    final Violation violation = new Violation(1, 1, "messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "Test.java", violation);
    logger.fileStarted(ev);
    logger.addError(ev);
    logger.fileFinished(ev);
    logger.auditFinished(null);
    verifyXml(getPath("ExpectedXMLLoggerError.xml"), outStream, violation.getViolation());
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 88 with AuditEvent

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

the class XMLLoggerTest method testAddIgnored.

@Test
public void testAddIgnored() throws Exception {
    final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
    logger.auditStarted(null);
    final Violation violation = new Violation(1, 1, "messages.properties", "key", null, SeverityLevel.IGNORE, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "Test.java", violation);
    logger.addError(ev);
    logger.auditFinished(null);
    verifyXml(getPath("ExpectedXMLLoggerEmpty.xml"), outStream);
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 89 with AuditEvent

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

the class XMLLoggerTest method testFileFinished.

@Test
public void testFileFinished() throws Exception {
    final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
    logger.auditStarted(null);
    final AuditEvent ev = new AuditEvent(this, "Test.java");
    logger.fileFinished(ev);
    logger.auditFinished(null);
    verifyXml(getPath("ExpectedXMLLogger.xml"), outStream);
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 90 with AuditEvent

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

the class XMLLoggerTest method testAddExceptionBeforeFileFinished.

@Test
public void testAddExceptionBeforeFileFinished() throws Exception {
    final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
    logger.auditStarted(null);
    final Violation violation = new Violation(1, 1, "messages.properties", null, null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "Test.java", violation);
    logger.addException(ev, new TestException("msg", new RuntimeException("msg")));
    final AuditEvent fileFinishedEvent = new AuditEvent(this, "Test.java");
    logger.fileFinished(fileFinishedEvent);
    logger.auditFinished(null);
    verifyXml(getPath("ExpectedXMLLoggerException3.xml"), outStream);
    assertWithMessage("Invalid close count").that(outStream.getCloseCount()).isEqualTo(1);
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.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