use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SarifLoggerTest method testLineOnly.
@Test
public void testLineOnly() throws IOException {
final SarifLogger logger = new SarifLogger(outStream, AutomaticBean.OutputStreamOptions.CLOSE);
logger.auditStarted(null);
final Violation violation = new Violation(1, 0, "messages.properties", "ruleId", null, null, getClass(), "found an error");
final AuditEvent ev = new AuditEvent(this, "Test.java", violation);
logger.fileStarted(ev);
logger.addError(ev);
logger.fileFinished(ev);
logger.auditFinished(null);
verifyContent(getPath("ExpectedSarifLoggerLineOnly.sarif"), outStream);
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SarifLoggerTest method testAddError.
@Test
public void testAddError() throws IOException {
final SarifLogger logger = new SarifLogger(outStream, AutomaticBean.OutputStreamOptions.CLOSE);
logger.auditStarted(null);
final Violation violation = new Violation(1, 1, "messages.properties", "ruleId", null, SeverityLevel.ERROR, null, getClass(), "found an error");
final AuditEvent ev = new AuditEvent(this, "Test.java", violation);
logger.fileStarted(ev);
logger.addError(ev);
logger.fileFinished(ev);
logger.auditFinished(null);
verifyContent(getPath("ExpectedSarifLoggerSingleError.sarif"), outStream);
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SarifLoggerTest method testAddErrors.
@Test
public void testAddErrors() throws IOException {
final SarifLogger logger = new SarifLogger(outStream, AutomaticBean.OutputStreamOptions.CLOSE);
logger.auditStarted(null);
final Violation violation = new Violation(1, 1, "messages.properties", "ruleId", null, SeverityLevel.INFO, null, getClass(), "found an error");
final AuditEvent ev = new AuditEvent(this, "Test.java", violation);
final Violation violation2 = new Violation(1, 1, "messages.properties", "ruleId2", null, SeverityLevel.IGNORE, null, getClass(), "found another error");
final AuditEvent ev2 = new AuditEvent(this, "Test.java", violation2);
logger.fileStarted(ev);
logger.addError(ev);
logger.fileFinished(ev);
logger.fileStarted(ev2);
logger.addError(ev2);
logger.fileFinished(ev2);
logger.auditFinished(null);
verifyContent(getPath("ExpectedSarifLoggerDoubleError.sarif"), outStream);
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class SarifLoggerTest method testAddException.
@Test
public void testAddException() throws IOException {
final SarifLogger logger = new SarifLogger(outStream, AutomaticBean.OutputStreamOptions.CLOSE);
logger.auditStarted(null);
final Violation message = new Violation(1, 1, "messages.properties", "null", null, null, getClass(), "found an error");
final AuditEvent ev = new AuditEvent(this, null, message);
logger.fileStarted(ev);
logger.addException(ev, new TestException("msg", new RuntimeException("msg")));
logger.fileFinished(ev);
logger.auditFinished(null);
verifyContent(getPath("ExpectedSarifLoggerSingleException.sarif"), outStream);
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class CheckerTest method testAddListener.
@Test
public void testAddListener() throws Exception {
final Checker checker = new Checker();
final DebugAuditAdapter auditAdapter = new DebugAuditAdapter();
checker.addListener(auditAdapter);
// Let's try fire some events
getFireAuditStartedMethod().invoke(checker);
assertWithMessage("Checker.fireAuditStarted() doesn't call listener").that(auditAdapter.wasCalled()).isTrue();
assertWithMessage("Checker.fireAuditStarted() doesn't pass event").that(auditAdapter.wasEventPassed()).isTrue();
auditAdapter.resetListener();
getFireAuditFinished().invoke(checker);
assertWithMessage("Checker.fireAuditFinished() doesn't call listener").that(auditAdapter.wasCalled()).isTrue();
assertWithMessage("Checker.fireAuditFinished() doesn't pass event").that(auditAdapter.wasEventPassed()).isTrue();
auditAdapter.resetListener();
checker.fireFileStarted("Some File Name");
assertWithMessage("Checker.fireFileStarted() doesn't call listener").that(auditAdapter.wasCalled()).isTrue();
assertWithMessage("Checker.fireFileStarted() doesn't pass event").that(auditAdapter.wasEventPassed()).isTrue();
auditAdapter.resetListener();
checker.fireFileFinished("Some File Name");
assertWithMessage("Checker.fireFileFinished() doesn't call listener").that(auditAdapter.wasCalled()).isTrue();
assertWithMessage("Checker.fireFileFinished() doesn't pass event").that(auditAdapter.wasEventPassed()).isTrue();
auditAdapter.resetListener();
final SortedSet<Violation> violations = new TreeSet<>();
violations.add(new Violation(1, 0, "a Bundle", "message.key", new Object[] { "arg" }, null, getClass(), null));
checker.fireErrors("Some File Name", violations);
assertWithMessage("Checker.fireErrors() doesn't call listener").that(auditAdapter.wasCalled()).isTrue();
assertWithMessage("Checker.fireErrors() doesn't pass event").that(auditAdapter.wasEventPassed()).isTrue();
}
Aggregations