Search in sources :

Example 91 with AuditEvent

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

the class XpathFileGeneratorAuditListenerTest method testCorrectTwo.

@Test
public void testCorrectTwo() {
    final AuditEvent event1 = createAuditEvent("InputXpathFileGeneratorAuditListener.java", SECOND_MESSAGE);
    final AuditEvent event2 = createAuditEvent("InputXpathFileGeneratorAuditListener.java", THIRD_MESSAGE);
    final String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + EOL + "<!DOCTYPE suppressions PUBLIC" + EOL + "    \"-//Checkstyle//DTD SuppressionXpathFilter Experimental Configuration 1.2" + "//EN\"" + EOL + "    \"https://checkstyle.org/dtds/suppressions_1_2_xpath_experimental.dtd\">" + EOL + "<suppressions>" + EOL + "<suppress-xpath" + EOL + "       files=\"InputXpathFileGeneratorAuditListener.java\"" + EOL + "       id=\"MyModule\"" + EOL + "       query=\"/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathFileGeneratorAuditListener']]" + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='sort']]\"/>" + EOL + "<suppress-xpath" + EOL + "       files=\"InputXpathFileGeneratorAuditListener.java\"" + EOL + "       checks=\"NestedForDepthCheck\"" + EOL + "       query=\"/COMPILATION_UNIT/CLASS_DEF" + "[./IDENT[@text='InputXpathFileGeneratorAuditListener']]" + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='sort']]/SLIST/LITERAL_FOR/SLIST" + "/LITERAL_FOR\"/>" + EOL + "</suppressions>" + EOL;
    verifyOutput(expected, event1, event2);
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 92 with AuditEvent

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

the class XpathFileGeneratorAuditListenerTest method testFileFinished.

@Test
public void testFileFinished() {
    final OutputStream out = new ByteArrayOutputStream();
    final XpathFileGeneratorAuditListener listener = new XpathFileGeneratorAuditListener(out, AutomaticBean.OutputStreamOptions.CLOSE);
    final AuditEvent ev = new AuditEvent(this, "Test.java", null);
    listener.fileFinished(ev);
    listener.auditFinished(null);
    final String actual = out.toString();
    assertWithMessage("Output should be empty").that(actual).isEmpty();
}
Also used : 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)

Example 93 with AuditEvent

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

the class AuditEventDefaultFormatterTest method testFormatModuleWithModuleId.

@Test
public void testFormatModuleWithModuleId() {
    final Violation violation = new Violation(1, 1, null, null, null, SeverityLevel.WARNING, "ModuleId", 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. [ModuleId]";
    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 94 with AuditEvent

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

the class AuditEventDefaultFormatterTest method testCalculateBufferLength.

@Test
public void testCalculateBufferLength() throws Exception {
    final Violation violation = new Violation(1, 1, "messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
    final AuditEvent auditEvent = new AuditEvent(new Object(), "fileName", violation);
    final int result = TestUtil.invokeStaticMethod(AuditEventDefaultFormatter.class, "calculateBufferLength", auditEvent, SeverityLevel.ERROR.ordinal());
    assertWithMessage("Buffer length is not expected").that(result).isEqualTo(54);
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test)

Example 95 with AuditEvent

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

the class AuditEventDefaultFormatterTest method testFormatFullyQualifiedModuleNameContainsCheckSuffix.

@Test
public void testFormatFullyQualifiedModuleNameContainsCheckSuffix() {
    final Violation violation = new Violation(1, 1, null, null, null, SeverityLevel.WARNING, null, TestModuleCheck.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)

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