Search in sources :

Example 26 with LocalizedMessage

use of com.puppycrawl.tools.checkstyle.api.LocalizedMessage 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)

Example 27 with LocalizedMessage

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

the class SuppressElementTest method testDecideByFileNameAndModuleMatchingCheckRegExpNotMatch.

@Test
public void testDecideByFileNameAndModuleMatchingCheckRegExpNotMatch() {
    final LocalizedMessage message = new LocalizedMessage(10, 10, "", "", null, null, getClass(), null);
    final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
    filter.setChecks("NON_EXISTING_CHECK");
    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 28 with LocalizedMessage

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

the class SuppressElementTest method testDecideByLine.

@Test
public void testDecideByLine() {
    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 line
    filter.setLines("1-10");
    assertFalse("In range 1-10", filter.accept(ev));
    filter.setLines("1-9, 11");
    assertTrue("Not in 1-9, 11", filter.accept(ev));
    filter.setLines(null);
    assertFalse("none", filter.accept(ev));
}
Also used : AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Example 29 with LocalizedMessage

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

the class SuppressElementTest method testDecideByFileNameAndModuleMatchingModuleEqual.

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

Example 30 with LocalizedMessage

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

the class SeverityMatchFilterTest method testAcceptOnMatch.

@Test
public void testAcceptOnMatch() {
    filter.setSeverity(SeverityLevel.INFO);
    filter.setAcceptOnMatch(false);
    final AuditEvent ev = new AuditEvent(this, "Test.java");
    // event with no message has severity level INFO
    assertFalse("no message", filter.accept(ev));
    final SeverityLevel errorLevel = SeverityLevel.ERROR;
    final LocalizedMessage errorMessage = new LocalizedMessage(0, 0, "", "", null, errorLevel, null, getClass(), null);
    final AuditEvent ev2 = new AuditEvent(this, "ATest.java", errorMessage);
    assertTrue("level:" + errorLevel, filter.accept(ev2));
    final SeverityLevel infoLevel = SeverityLevel.INFO;
    final LocalizedMessage infoMessage = new LocalizedMessage(0, 0, "", "", null, infoLevel, null, getClass(), null);
    final AuditEvent ev3 = new AuditEvent(this, "ATest.java", infoMessage);
    assertFalse("level:" + infoLevel, filter.accept(ev3));
}
Also used : SeverityLevel(com.puppycrawl.tools.checkstyle.api.SeverityLevel) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) LocalizedMessage(com.puppycrawl.tools.checkstyle.api.LocalizedMessage) Test(org.junit.Test)

Aggregations

LocalizedMessage (com.puppycrawl.tools.checkstyle.api.LocalizedMessage)37 Test (org.junit.Test)29 AuditEvent (com.puppycrawl.tools.checkstyle.api.AuditEvent)24 TreeSet (java.util.TreeSet)6 File (java.io.File)4 ArrayList (java.util.ArrayList)4 SeverityLevel (com.puppycrawl.tools.checkstyle.api.SeverityLevel)3 Checker (com.puppycrawl.tools.checkstyle.Checker)2 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)2 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)2 IOException (java.io.IOException)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 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 AuditListener (com.puppycrawl.tools.checkstyle.api.AuditListener)1 FileNotFoundException (java.io.FileNotFoundException)1 RandomAccessFile (java.io.RandomAccessFile)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1