Search in sources :

Example 56 with AuditEvent

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

the class SuppressFilterElementTest method testDecideByFileNameAndModuleMatchingMessageNull.

@Test
public void testDecideByFileNameAndModuleMatchingMessageNull() {
    final AuditEvent ev = new AuditEvent(this, "ATest.java", null);
    assertWithMessage("Filter should accept valid event").that(filter.accept(ev)).isTrue();
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test) TreeWalkerTest(com.puppycrawl.tools.checkstyle.TreeWalkerTest)

Example 57 with AuditEvent

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

the class SuppressFilterElementTest method testDecideByFileNameAndModuleMatchingRegExpNotMatch.

@Test
public void testDecideByFileNameAndModuleMatchingRegExpNotMatch() {
    final Violation message = new Violation(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "T1est", message);
    assertWithMessage("Filter should accept valid event").that(filter.accept(ev)).isTrue();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test) TreeWalkerTest(com.puppycrawl.tools.checkstyle.TreeWalkerTest)

Example 58 with AuditEvent

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

the class SuppressFilterElementTest method testDecideByColumn.

@Test
public void testDecideByColumn() {
    final Violation violation = new Violation(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", violation);
    final SuppressFilterElement filter1 = new SuppressFilterElement("Test", "Test", null, null, null, "1-10");
    final SuppressFilterElement filter2 = new SuppressFilterElement("Test", "Test", null, null, null, "1-9, 11");
    // deny because there are matches on file name, check name, and column
    assertWithMessage("In range 1-10").that(filter1.accept(ev)).isFalse();
    assertWithMessage("Not in 1-9, 1)").that(filter2.accept(ev)).isTrue();
}
Also used : Violation(com.puppycrawl.tools.checkstyle.api.Violation) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.jupiter.api.Test) TreeWalkerTest(com.puppycrawl.tools.checkstyle.TreeWalkerTest)

Example 59 with AuditEvent

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

the class AuditEventDefaultFormatterTest method testFormatModuleNameDoesNotContainCheckSuffix.

@Test
public void testFormatModuleNameDoesNotContainCheckSuffix() {
    final AuditEvent mock = PowerMockito.mock(AuditEvent.class);
    when(mock.getSourceName()).thenReturn("TestModule");
    when(mock.getSeverityLevel()).thenReturn(SeverityLevel.WARNING);
    when(mock.getLine()).thenReturn(1);
    when(mock.getColumn()).thenReturn(1);
    when(mock.getMessage()).thenReturn("Mocked message.");
    when(mock.getFileName()).thenReturn("InputMockFile.java");
    final AuditEventFormatter formatter = new AuditEventDefaultFormatter();
    final String expected = "[WARN] InputMockFile.java:1:1: Mocked message. [TestModule]";
    assertEquals(expected, formatter.format(mock));
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 60 with AuditEvent

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

the class SuppressionFilterTest method testNonExistanceSuppressionUrlWithTrueOptional.

@Test
public void testNonExistanceSuppressionUrlWithTrueOptional() throws Exception {
    final String fileName = "http://checkstyle.sourceforge.net/non_existing_suppression.xml";
    final boolean optional = true;
    final SuppressionFilter filter = createSupressionFilter(fileName, optional);
    final AuditEvent ev = new AuditEvent(this, "AnyFile.java", null);
    assertTrue(filter.accept(ev));
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.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