Search in sources :

Example 16 with Violation

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

the class XMLLoggerTest method testAddErrorOnZeroColumns.

@Test
public void testAddErrorOnZeroColumns() throws Exception {
    final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
    logger.auditStarted(null);
    final Violation violation = new Violation(1, 0, "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("ExpectedXMLLoggerErrorZeroColumn.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 17 with Violation

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

the class XMLLoggerTest method testAddExceptionAfterFileStarted.

@Test
public void testAddExceptionAfterFileStarted() throws Exception {
    final XMLLogger logger = new XMLLogger(outStream, OutputStreamOptions.CLOSE);
    logger.auditStarted(null);
    final AuditEvent fileStartedEvent = new AuditEvent(this, "Test.java");
    logger.fileStarted(fileStartedEvent);
    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")));
    logger.fileFinished(ev);
    logger.auditFinished(null);
    verifyXml(getPath("ExpectedXMLLoggerException2.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)

Example 18 with Violation

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

the class XMLLoggerTest method testAddErrorModuleId.

@Test
public void testAddErrorModuleId() 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, "module", getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "Test.java", violation);
    logger.addError(ev);
    logger.auditFinished(null);
    verifyXml(getPath("ExpectedXMLLoggerErrorModuleId.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 19 with Violation

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

the class XMLLoggerTest method testAddExceptionWithNullFileName.

@Test
public void testAddExceptionWithNullFileName() 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, null, violation);
    logger.addException(ev, new TestException("msg", new RuntimeException("msg")));
    logger.auditFinished(null);
    verifyXml(getPath("ExpectedXMLLoggerExceptionNullFileName.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)

Example 20 with Violation

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

the class XpathFileGeneratorAuditListenerTest method testAddException.

@Test
public void testAddException() {
    final OutputStream out = new ByteArrayOutputStream();
    final XpathFileGeneratorAuditListener logger = new XpathFileGeneratorAuditListener(out, AutomaticBean.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);
    try {
        logger.addException(ev, null);
        assertWithMessage("Exception is excepted").fail();
    } catch (UnsupportedOperationException ex) {
        assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo("Operation is not supported");
    }
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CloseAndFlushTestByteArrayOutputStream(com.puppycrawl.tools.checkstyle.internal.utils.CloseAndFlushTestByteArrayOutputStream) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CloseAndFlushTestByteArrayOutputStream(com.puppycrawl.tools.checkstyle.internal.utils.CloseAndFlushTestByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

Violation (com.puppycrawl.tools.checkstyle.api.Violation)109 Test (org.junit.jupiter.api.Test)98 AuditEvent (com.puppycrawl.tools.checkstyle.api.AuditEvent)51 TreeWalkerAuditEvent (com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent)17 File (java.io.File)14 TreeWalkerTest (com.puppycrawl.tools.checkstyle.TreeWalkerTest)13 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)10 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)8 FileContents (com.puppycrawl.tools.checkstyle.api.FileContents)7 FileText (com.puppycrawl.tools.checkstyle.api.FileText)7 TreeSet (java.util.TreeSet)6 DetailAstImpl (com.puppycrawl.tools.checkstyle.DetailAstImpl)5 ParseErrorMessage (com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage)3 SeverityLevel (com.puppycrawl.tools.checkstyle.api.SeverityLevel)3 DebugAuditAdapter (com.puppycrawl.tools.checkstyle.internal.testmodules.DebugAuditAdapter)3 DebugFilter (com.puppycrawl.tools.checkstyle.internal.testmodules.DebugFilter)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStream (java.io.OutputStream)3 Method (java.lang.reflect.Method)3 Checker (com.puppycrawl.tools.checkstyle.Checker)2