Search in sources :

Example 6 with AuditEvent

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

the class AuditEventDefaultFormatterTest method testFormatFullyQualifiedModuleNameDoesNotContainCheckSuffix.

@Test
public void testFormatFullyQualifiedModuleNameDoesNotContainCheckSuffix() {
    final AuditEvent mock = PowerMockito.mock(AuditEvent.class);
    when(mock.getSourceName()).thenReturn("com.test.package.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 7 with AuditEvent

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

the class SuppressionFilterTest method testAcceptOnNullFile.

@Test
public void testAcceptOnNullFile() throws CheckstyleException {
    final String fileName = null;
    final boolean optional = false;
    final SuppressionFilter filter = createSupressionFilter(fileName, optional);
    final AuditEvent ev = new AuditEvent(this, "AnyJava.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)

Example 8 with AuditEvent

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

the class SuppressionFilterTest method testAccept.

@Test
public void testAccept() throws CheckstyleException {
    final String fileName = "src/test/resources/com/puppycrawl/tools/checkstyle/filters/" + "suppressions_none.xml";
    final boolean optional = false;
    final SuppressionFilter filter = createSupressionFilter(fileName, optional);
    final AuditEvent ev = new AuditEvent(this, "ATest.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)

Example 9 with AuditEvent

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

the class SuppressionFilterTest method testExistingSuppressionFileWithTrueOptional.

@Test
public void testExistingSuppressionFileWithTrueOptional() throws Exception {
    final String fileName = "src/test/resources/com/puppycrawl/tools/checkstyle/filters/" + "suppressions_none.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)

Example 10 with AuditEvent

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

the class SuppressElementTest method testDecideByFileNameAndModuleMatchingRegExpNotMatch.

@Test
public void testDecideByFileNameAndModuleMatchingRegExpNotMatch() {
    final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "T1est", message);
    assertTrue(filter.accept(ev));
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Aggregations

AuditEvent (com.puppycrawl.tools.checkstyle.api.AuditEvent)47 Test (org.junit.Test)38 LocalizedMessage (com.puppycrawl.tools.checkstyle.api.LocalizedMessage)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 SeverityLevel (com.puppycrawl.tools.checkstyle.api.SeverityLevel)4 ArrayList (java.util.ArrayList)4 AuditListener (com.puppycrawl.tools.checkstyle.api.AuditListener)3 Checker (com.puppycrawl.tools.checkstyle.Checker)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 Field (java.lang.reflect.Field)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 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 List (java.util.List)1 SinkEventAttributeSet (org.apache.maven.doxia.sink.SinkEventAttributeSet)1