Search in sources :

Example 21 with Violation

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

the class DetailNodeTreeStringPrinterTest method testWrongSingletonParseErrorMessage.

@Test
public void testWrongSingletonParseErrorMessage() throws Exception {
    final String actual = TestUtil.invokeStaticMethod(DetailNodeTreeStringPrinter.class, "getParseErrorMessage", new ParseErrorMessage(100, MSG_JAVADOC_WRONG_SINGLETON_TAG, 9, "tag"));
    final Violation violation = new Violation(100, "com.puppycrawl.tools.checkstyle.checks.javadoc.messages", MSG_JAVADOC_WRONG_SINGLETON_TAG, new Object[] { 9, "tag" }, "", DetailNodeTreeStringPrinter.class, null);
    final String expected = "[ERROR:100] " + violation.getViolation();
    assertWithMessage("Javadoc parse error violation for void elements with close tag " + "doesn't meet expectations").that(actual).isEqualTo(expected);
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) ParseErrorMessage(com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage) Test(org.junit.jupiter.api.Test)

Example 22 with Violation

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

the class DetailNodeTreeStringPrinterTest method testMissedHtmlTagParseErrorMessage.

@Test
public void testMissedHtmlTagParseErrorMessage() throws Exception {
    final String actual = TestUtil.invokeStaticMethod(DetailNodeTreeStringPrinter.class, "getParseErrorMessage", new ParseErrorMessage(35, MSG_JAVADOC_MISSED_HTML_CLOSE, 7, "xyz"));
    final Violation violation = new Violation(35, "com.puppycrawl.tools.checkstyle.checks.javadoc.messages", MSG_JAVADOC_MISSED_HTML_CLOSE, new Object[] { 7, "xyz" }, "", DetailNodeTreeStringPrinter.class, null);
    final String expected = "[ERROR:35] " + violation.getViolation();
    assertWithMessage("Javadoc parse error violation for missed HTML tag " + "doesn't meet expectations").that(actual).isEqualTo(expected);
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) ParseErrorMessage(com.puppycrawl.tools.checkstyle.JavadocDetailNodeParser.ParseErrorMessage) Test(org.junit.jupiter.api.Test)

Example 23 with Violation

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

the class AuditEventDefaultFormatterTest method testFormatFullyQualifiedModuleNameDoesNotContainCheckSuffix.

@Test
public void testFormatFullyQualifiedModuleNameDoesNotContainCheckSuffix() {
    final Violation violation = new Violation(1, 1, null, null, null, SeverityLevel.WARNING, null, TestModule.class, "Mocked violation.");
    final AuditEvent event = new AuditEvent("", "InputMockFile.java", violation);
    final AuditEventFormatter formatter = new AuditEventDefaultFormatter();
    final String expected = "[WARN] InputMockFile.java:1:1: Mocked violation. " + "[AuditEventDefaultFormatterTest$TestModule]";
    assertWithMessage("Invalid format").that(formatter.format(event)).isEqualTo(expected);
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 24 with Violation

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

the class DefaultLoggerTest method testAddError.

@Test
public void testAddError() throws Exception {
    final OutputStream infoStream = new ByteArrayOutputStream();
    final OutputStream errorStream = new ByteArrayOutputStream();
    final Method auditStartMessage = getAuditStartMessage();
    final Method auditFinishMessage = getAuditFinishMessage();
    final DefaultLogger dl = new DefaultLogger(infoStream, AutomaticBean.OutputStreamOptions.CLOSE, errorStream, AutomaticBean.OutputStreamOptions.CLOSE);
    dl.finishLocalSetup();
    dl.auditStarted(null);
    dl.addError(new AuditEvent(this, "fileName", new Violation(1, 2, "bundle", "key", null, null, getClass(), "customViolation")));
    dl.auditFinished(null);
    auditFinishMessage.setAccessible(true);
    auditStartMessage.setAccessible(true);
    assertWithMessage("expected output").that(infoStream.toString()).isEqualTo(auditStartMessage.invoke(getAuditStartMessageClass()) + System.lineSeparator() + auditFinishMessage.invoke(getAuditFinishMessageClass()) + System.lineSeparator());
    assertWithMessage("expected output").that(errorStream.toString()).isEqualTo("[ERROR] fileName:1:2: customViolation [DefaultLoggerTest]" + System.lineSeparator());
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 25 with Violation

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

the class DefaultLoggerTest method testAddErrorModuleId.

@Test
public void testAddErrorModuleId() throws Exception {
    final OutputStream infoStream = new ByteArrayOutputStream();
    final OutputStream errorStream = new ByteArrayOutputStream();
    final Method auditFinishMessage = getAuditFinishMessage();
    final Method auditStartMessage = getAuditStartMessage();
    final DefaultLogger dl = new DefaultLogger(infoStream, OutputStreamOptions.CLOSE, errorStream, OutputStreamOptions.CLOSE);
    dl.finishLocalSetup();
    dl.auditStarted(null);
    dl.addError(new AuditEvent(this, "fileName", new Violation(1, 2, "bundle", "key", null, "moduleId", getClass(), "customViolation")));
    dl.auditFinished(null);
    auditFinishMessage.setAccessible(true);
    auditStartMessage.setAccessible(true);
    assertWithMessage("expected output").that(infoStream.toString()).isEqualTo(auditStartMessage.invoke(getAuditStartMessageClass()) + System.lineSeparator() + auditFinishMessage.invoke(getAuditFinishMessageClass()) + System.lineSeparator());
    assertWithMessage("expected output").that(errorStream.toString()).isEqualTo("[ERROR] fileName:1:2: customViolation [moduleId]" + System.lineSeparator());
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Method(java.lang.reflect.Method) 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