Search in sources :

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

Example 62 with AuditEvent

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

the class SuppressionFilterTest method testNonExistanceSuppressionFileWithTrueOptional.

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

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

the class SuppressElementTest method testDecideByFileNameAndModuleMatchingModuleNotEqual.

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

Example 64 with AuditEvent

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

the class SuppressElementTest method testDecideDefault.

@Test
public void testDecideDefault() {
    final AuditEvent ev = new AuditEvent(this, "Test.java");
    assertTrue(ev.getFileName(), filter.accept(ev));
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) Test(org.junit.Test)

Example 65 with AuditEvent

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

the class SuppressElementTest method testDecideByColumn.

@Test
public void testDecideByColumn() {
    final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
    //deny because there are matches on file name, check name, and column
    filter.setColumns("1-10");
    assertFalse("In range 1-10", filter.accept(ev));
    filter.setColumns("1-9, 11");
    assertTrue("Not in 1-9, 1)", 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)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