use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class XpathFilterElementTest method testNonMatchingModuleId.
@Test
public void testNonMatchingModuleId() throws Exception {
final XpathFilterElement filter = new XpathFilterElement("InputXpathFilterElementSuppressByXpath", "Test", null, "id19", null);
final Violation message = new Violation(3, 0, TokenTypes.CLASS_DEF, "", "", null, null, "id20", getClass(), null);
final TreeWalkerAuditEvent ev = new TreeWalkerAuditEvent(fileContents, file.getName(), message, JavaParser.parseFile(file, JavaParser.Options.WITHOUT_COMMENTS));
assertWithMessage("Event should be accepted").that(filter.accept(ev)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SeverityMatchFilterTest method testSeverity.
@Test
public void testSeverity() {
filter.setSeverity(SeverityLevel.INFO);
final AuditEvent ev = new AuditEvent(this, "Test.java");
// event with no message has severity level INFO
assertWithMessage("no message").that(filter.accept(ev)).isTrue();
final SeverityLevel errorLevel = SeverityLevel.ERROR;
final Violation errorMessage = new Violation(1, 0, "", "", null, errorLevel, null, getClass(), null);
final AuditEvent ev2 = new AuditEvent(this, "ATest.java", errorMessage);
assertWithMessage("level:" + errorLevel).that(filter.accept(ev2)).isFalse();
final SeverityLevel infoLevel = SeverityLevel.INFO;
final Violation infoMessage = new Violation(1, 0, "", "", null, infoLevel, null, getClass(), null);
final AuditEvent ev3 = new AuditEvent(this, "ATest.java", infoMessage);
assertWithMessage("level:" + infoLevel).that(filter.accept(ev3)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SeverityMatchFilterTest method testDefault.
@Test
public void testDefault() {
final AuditEvent ev = new AuditEvent(this, "Test.java");
assertWithMessage("no message").that(filter.accept(ev)).isFalse();
final SeverityLevel errorLevel = SeverityLevel.ERROR;
final Violation errorMessage = new Violation(1, 0, "", "", null, errorLevel, null, getClass(), null);
final AuditEvent ev2 = new AuditEvent(this, "ATest.java", errorMessage);
assertWithMessage("level:" + errorLevel).that(filter.accept(ev2)).isTrue();
final SeverityLevel infoLevel = SeverityLevel.INFO;
final Violation infoViolation = new Violation(1, 0, "", "", null, infoLevel, null, getClass(), null);
final AuditEvent ev3 = new AuditEvent(this, "ATest.java", infoViolation);
assertWithMessage("level:" + infoLevel).that(filter.accept(ev3)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SuppressFilterElementTest method testDecideByLine.
@Test
public void testDecideByLine() {
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, "1-10", null);
final SuppressFilterElement filter2 = new SuppressFilterElement("Test", "Test", null, null, "1-9, 11", null);
final SuppressFilterElement filter3 = new SuppressFilterElement("Test", "Test", null, null, null, null);
// deny because there are matches on file name, check name, and line
assertWithMessage("In range 1-10").that(filter1.accept(ev)).isFalse();
assertWithMessage("Not in 1-9, 11").that(filter2.accept(ev)).isTrue();
assertWithMessage("none").that(filter3.accept(ev)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SuppressFilterElementTest method testDecideByFileNameAndModuleMatchingCheckRegExpNotMatch.
@Test
public void testDecideByFileNameAndModuleMatchingCheckRegExpNotMatch() {
final Violation message = new Violation(10, 10, "", "", null, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
final SuppressFilterElement myFilter = new SuppressFilterElement("Test", "NON_EXISTENT_CHECK", null, "MyModule", null, null);
assertWithMessage("Filter should accept valid event").that(myFilter.accept(ev)).isTrue();
}
Aggregations