use of com.puppycrawl.tools.checkstyle.api.AuditEvent 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.AuditEvent in project checkstyle by checkstyle.
the class SuppressionFilterTest method testExistingSuppressionFileWithTrueOptional.
@Test
public void testExistingSuppressionFileWithTrueOptional() throws Exception {
final String fileName = getPath("InputSuppressionFilterNone.xml");
final boolean optional = true;
final SuppressionFilter filter = createSuppressionFilter(fileName, optional);
final AuditEvent ev = new AuditEvent(this, "AnyFile.java", null);
assertWithMessage("Suppression file with true optional was not accepted").that(filter.accept(ev)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.AuditEvent 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.AuditEvent in project checkstyle by checkstyle.
the class SuppressionFilterTest method testAccept.
@Test
public void testAccept() throws Exception {
final String fileName = getPath("InputSuppressionFilterNone.xml");
final boolean optional = false;
final SuppressionFilter filter = createSuppressionFilter(fileName, optional);
final AuditEvent ev = new AuditEvent(this, "ATest.java", null);
assertWithMessage("Audit event should be excepted when there are no suppressions").that(filter.accept(ev)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.api.AuditEvent in project checkstyle by checkstyle.
the class SuppressionFilterTest method testAcceptOnNullFile.
@Test
public void testAcceptOnNullFile() throws CheckstyleException {
final String fileName = null;
final boolean optional = false;
final SuppressionFilter filter = createSuppressionFilter(fileName, optional);
final AuditEvent ev = new AuditEvent(this, "AnyJava.java", null);
assertWithMessage("Audit event on null file should be excepted, but was not").that(filter.accept(ev)).isTrue();
}
Aggregations