use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SuppressWithPlainTextCommentFilterTest method testAcceptThrowsIllegalStateExceptionAsFileNotFound.
@Test
public void testAcceptThrowsIllegalStateExceptionAsFileNotFound() {
final Violation message = new Violation(1, 1, 1, TokenTypes.CLASS_DEF, "messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
final String fileName = "nonexisting_file";
final AuditEvent auditEvent = new AuditEvent(this, fileName, message);
final SuppressWithPlainTextCommentFilter filter = new SuppressWithPlainTextCommentFilter();
try {
filter.accept(auditEvent);
assertWithMessage(IllegalStateException.class.getSimpleName() + " is expected").fail();
} catch (IllegalStateException ex) {
assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo("Cannot read source file: " + fileName);
final Throwable cause = ex.getCause();
assertWithMessage("Exception cause has invalid type").that(cause).isInstanceOf(FileNotFoundException.class);
assertWithMessage("Invalid exception message").that(cause).hasMessageThat().isEqualTo(fileName + " (No such file or directory)");
}
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SuppressionFilterTest method testAcceptFalse.
@Test
public void testAcceptFalse() throws Exception {
final String fileName = getPath("InputSuppressionFilterSuppress.xml");
final boolean optional = false;
final SuppressionFilter filter = createSuppressionFilter(fileName, optional);
final Violation message = new Violation(1, 1, null, "msg", null, SeverityLevel.ERROR, null, getClass(), null);
final AuditEvent ev = new AuditEvent(this, "ATest.java", message);
assertWithMessage("Audit event should be rejected when there is a matching suppression").that(filter.accept(ev)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SuppressionXpathFilterTest method testReject.
@Test
public void testReject() throws Exception {
final boolean optional = false;
final SuppressionXpathFilter filter = createSuppressionXpathFilter(getPath("InputSuppressionXpathFilterIdAndQuery.xml"), optional);
final File file = new File(getPath("InputSuppressionXpathFilter.java"));
final Violation message = new Violation(3, 0, TokenTypes.CLASS_DEF, "", "", null, null, "777", getClass(), null);
final TreeWalkerAuditEvent ev = new TreeWalkerAuditEvent(null, "file1.java", message, JavaParser.parseFile(file, JavaParser.Options.WITHOUT_COMMENTS));
assertWithMessage("TreeWalker audit event should be rejected").that(filter.accept(ev)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class XpathFilterElementTest method testNonMatchingChecks.
@Test
public void testNonMatchingChecks() throws Exception {
final String xpath = "NON_MATCHING_QUERY";
final XpathFilterElement filter = new XpathFilterElement("InputXpathFilterElementSuppressByXpath", "NonMatchingRegexp", null, "id19", xpath);
final Violation message = new Violation(3, 0, TokenTypes.CLASS_DEF, "", "", null, null, "id19", 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 XpathFilterElementTest method testDecideByMessage.
@Test
public void testDecideByMessage() throws Exception {
final Violation message = new Violation(1, 0, TokenTypes.CLASS_DEF, "", "", null, null, null, getClass(), "Test");
final TreeWalkerAuditEvent ev = new TreeWalkerAuditEvent(fileContents, file.getName(), message, JavaParser.parseFile(file, JavaParser.Options.WITHOUT_COMMENTS));
final XpathFilterElement filter1 = new XpathFilterElement(null, null, "Test", null, null);
final XpathFilterElement filter2 = new XpathFilterElement(null, null, "Bad", null, null);
assertWithMessage("Message match").that(filter1.accept(ev)).isFalse();
assertWithMessage("Message not match").that(filter2.accept(ev)).isTrue();
}
Aggregations