use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class AuditEventDefaultFormatterTest method testCalculateBufferLength.
@Test
public void testCalculateBufferLength() throws Exception {
final Violation violation = new Violation(1, 1, "messages.properties", "key", null, SeverityLevel.ERROR, null, getClass(), null);
final AuditEvent auditEvent = new AuditEvent(new Object(), "fileName", violation);
final int result = TestUtil.invokeStaticMethod(AuditEventDefaultFormatter.class, "calculateBufferLength", auditEvent, SeverityLevel.ERROR.ordinal());
assertWithMessage("Buffer length is not expected").that(result).isEqualTo(54);
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class AuditEventDefaultFormatterTest method testFormatFullyQualifiedModuleNameContainsCheckSuffix.
@Test
public void testFormatFullyQualifiedModuleNameContainsCheckSuffix() {
final Violation violation = new Violation(1, 1, null, null, null, SeverityLevel.WARNING, null, TestModuleCheck.class, "Mocked violation.");
final AuditEvent event = new AuditEvent("", "InputMockFile.java", violation);
final AuditEventFormatter formatter = new AuditEventDefaultFormatter();
final String expected = "[WARN] InputMockFile.java:1:1: Mocked violation. " + "[AuditEventDefaultFormatterTest$TestModule]";
assertWithMessage("Invalid format").that(formatter.format(event)).isEqualTo(expected);
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class CheckerTest method testDestroy.
@Test
public void testDestroy() throws Exception {
final Checker checker = new Checker();
final DebugAuditAdapter auditAdapter = new DebugAuditAdapter();
checker.addListener(auditAdapter);
final TestFileSetCheck fileSet = new TestFileSetCheck();
checker.addFileSetCheck(fileSet);
final DebugFilter filter = new DebugFilter();
checker.addFilter(filter);
final TestBeforeExecutionFileFilter fileFilter = new TestBeforeExecutionFileFilter();
checker.addBeforeExecutionFileFilter(fileFilter);
// should remove all listeners, file sets, and filters
checker.destroy();
final File tempFile = File.createTempFile("junit", null, temporaryFolder);
checker.process(Collections.singletonList(tempFile));
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.destroy() doesn't remove listeners.").that(auditAdapter.wasCalled()).isFalse();
assertWithMessage("Checker.destroy() doesn't remove file sets.").that(fileSet.wasCalled()).isFalse();
assertWithMessage("Checker.destroy() doesn't remove filters.").that(filter.wasCalled()).isFalse();
assertWithMessage("Checker.destroy() doesn't remove file filters.").that(fileFilter.wasCalled()).isFalse();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class CheckerTest method testRemoveFilter.
@Test
public void testRemoveFilter() {
final Checker checker = new Checker();
final DebugFilter filter = new DebugFilter();
final DebugFilter f2 = new DebugFilter();
checker.addFilter(filter);
checker.addFilter(f2);
checker.removeFilter(filter);
f2.resetFilter();
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 filter").that(f2.wasCalled()).isTrue();
assertWithMessage("Checker.fireErrors() does call removed filter").that(filter.wasCalled()).isFalse();
}
use of com.puppycrawl.tools.checkstyle.api.Violation in project checkstyle by checkstyle.
the class CheckerTest method testRemoveListener.
@Test
public void testRemoveListener() throws Exception {
final Checker checker = new Checker();
final DebugAuditAdapter auditAdapter = new DebugAuditAdapter();
final DebugAuditAdapter aa2 = new DebugAuditAdapter();
checker.addListener(auditAdapter);
checker.addListener(aa2);
checker.removeListener(auditAdapter);
// Let's try fire some events
getFireAuditStartedMethod().invoke(checker);
assertWithMessage("Checker.fireAuditStarted() doesn't call listener").that(aa2.wasCalled()).isTrue();
assertWithMessage("Checker.fireAuditStarted() does call removed listener").that(auditAdapter.wasCalled()).isFalse();
aa2.resetListener();
getFireAuditFinished().invoke(checker);
assertWithMessage("Checker.fireAuditFinished() doesn't call listener").that(aa2.wasCalled()).isTrue();
assertWithMessage("Checker.fireAuditFinished() does call removed listener").that(auditAdapter.wasCalled()).isFalse();
aa2.resetListener();
checker.fireFileStarted("Some File Name");
assertWithMessage("Checker.fireFileStarted() doesn't call listener").that(aa2.wasCalled()).isTrue();
assertWithMessage("Checker.fireFileStarted() does call removed listener").that(auditAdapter.wasCalled()).isFalse();
aa2.resetListener();
checker.fireFileFinished("Some File Name");
assertWithMessage("Checker.fireFileFinished() doesn't call listener").that(aa2.wasCalled()).isTrue();
assertWithMessage("Checker.fireFileFinished() does call removed listener").that(auditAdapter.wasCalled()).isFalse();
aa2.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(aa2.wasCalled()).isTrue();
assertWithMessage("Checker.fireErrors() does call removed listener").that(auditAdapter.wasCalled()).isFalse();
}
Aggregations