Search in sources :

Example 26 with AuditEvent

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

the class XMLLoggerTest method testAddError.

@Test
public void testAddError() throws IOException {
    final XMLLogger logger = new XMLLogger(outStream, true);
    logger.auditStarted(null);
    final LocalizedMessage message = new LocalizedMessage(1, 1, "messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "Test.java", message);
    logger.addError(ev);
    logger.auditFinished(null);
    final String[] expectedLines = { "<error line=\"1\" column=\"1\" severity=\"error\" message=\"key\"" + " source=\"com.puppycrawl.tools.checkstyle.XMLLoggerTest\"/>" };
    verifyLines(expectedLines);
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Example 27 with AuditEvent

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

the class XMLLoggerTest method testFileFinished.

@Test
public void testFileFinished() throws IOException {
    final XMLLogger logger = new XMLLogger(outStream, true);
    logger.auditStarted(null);
    final AuditEvent ev = new AuditEvent(this, "Test.java");
    logger.fileFinished(ev);
    logger.auditFinished(null);
    final String[] expectedLines = { "</file>" };
    verifyLines(expectedLines);
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.Test)

Example 28 with AuditEvent

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

the class XMLLoggerTest method testAddIgnored.

@Test
public void testAddIgnored() throws IOException {
    final XMLLogger logger = new XMLLogger(outStream, true);
    logger.auditStarted(null);
    final LocalizedMessage message = new LocalizedMessage(1, 1, "messages.properties", "key", null, SeverityLevel.IGNORE, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "Test.java", message);
    logger.addError(ev);
    logger.auditFinished(null);
    final String[] expectedLines = CommonUtils.EMPTY_STRING_ARRAY;
    verifyLines(expectedLines);
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Example 29 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)

Example 30 with AuditEvent

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

the class SuppressionFilterTest method testExistingConfigWithTrueOptionalThrowsIoErrorWhileClosing.

@Test
public void testExistingConfigWithTrueOptionalThrowsIoErrorWhileClosing() throws Exception {
    final InputStream inputStream = PowerMockito.mock(InputStream.class);
    Mockito.doThrow(IOException.class).when(inputStream).close();
    final URL url = PowerMockito.mock(URL.class);
    BDDMockito.given(url.openStream()).willReturn(inputStream);
    final URI uri = PowerMockito.mock(URI.class);
    BDDMockito.given(uri.toURL()).willReturn(url);
    PowerMockito.mockStatic(CommonUtils.class);
    final String fileName = "src/test/resources/com/puppycrawl/tools/checkstyle/filters/" + "suppressions_none.xml";
    BDDMockito.given(CommonUtils.getUriByFilename(fileName)).willReturn(uri);
    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 : InputStream(java.io.InputStream) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) URI(java.net.URI) URL(java.net.URL) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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