use of com.puppycrawl.tools.checkstyle.internal.testmodules.TestBeforeExecutionFileFilter in project checkstyle by checkstyle.
the class CheckerTest method testRemoveBeforeExecutionFileFilter.
@Test
public void testRemoveBeforeExecutionFileFilter() throws Exception {
final Checker checker = new Checker();
final TestBeforeExecutionFileFilter filter = new TestBeforeExecutionFileFilter();
final TestBeforeExecutionFileFilter f2 = new TestBeforeExecutionFileFilter();
checker.addBeforeExecutionFileFilter(filter);
checker.addBeforeExecutionFileFilter(f2);
checker.removeBeforeExecutionFileFilter(filter);
f2.resetFilter();
checker.process(Collections.singletonList(new File("dummy.java")));
assertWithMessage("Checker.acceptFileStarted() doesn't call filter").that(f2.wasCalled()).isTrue();
assertWithMessage("Checker.acceptFileStarted() does call removed filter").that(filter.wasCalled()).isFalse();
}
use of com.puppycrawl.tools.checkstyle.internal.testmodules.TestBeforeExecutionFileFilter 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.internal.testmodules.TestBeforeExecutionFileFilter in project checkstyle by checkstyle.
the class CheckerTest method testAddBeforeExecutionFileFilter.
@Test
public void testAddBeforeExecutionFileFilter() throws Exception {
final Checker checker = new Checker();
final TestBeforeExecutionFileFilter filter = new TestBeforeExecutionFileFilter();
checker.addBeforeExecutionFileFilter(filter);
filter.resetFilter();
checker.process(Collections.singletonList(new File("dummy.java")));
assertWithMessage("Checker.acceptFileStarted() doesn't call filter").that(filter.wasCalled()).isTrue();
}
use of com.puppycrawl.tools.checkstyle.internal.testmodules.TestBeforeExecutionFileFilter in project checkstyle by checkstyle.
the class CheckerTest method testAddBeforeExecutionFileFilterAsChild.
@Test
public void testAddBeforeExecutionFileFilterAsChild() throws Exception {
final Checker checker = new Checker();
final TestBeforeExecutionFileFilter fileFilter = new TestBeforeExecutionFileFilter();
final PackageObjectFactory factory = new PackageObjectFactory(new HashSet<>(), Thread.currentThread().getContextClassLoader()) {
@Override
public Object createModule(String name) throws CheckstyleException {
Object filter = fileFilter;
if (!name.equals(TestBeforeExecutionFileFilter.class.getName())) {
filter = super.createModule(name);
}
return filter;
}
};
checker.setModuleFactory(factory);
checker.setupChild(createModuleConfig(TestBeforeExecutionFileFilter.class));
checker.process(Collections.singletonList(new File("dummy.java")));
assertWithMessage("Checker.acceptFileStarted() doesn't call listener").that(fileFilter.wasCalled()).isTrue();
}
Aggregations