use of com.puppycrawl.tools.checkstyle.internal.testmodules.DebugAuditAdapter in project checkstyle by checkstyle.
the class CheckerTest method testSetupChildListener.
@Test
public void testSetupChildListener() throws Exception {
final Checker checker = new Checker();
final PackageObjectFactory factory = new PackageObjectFactory(new HashSet<>(), Thread.currentThread().getContextClassLoader());
checker.setModuleFactory(factory);
final Configuration config = new DefaultConfiguration(DebugAuditAdapter.class.getCanonicalName());
checker.setupChild(config);
final List<AuditListener> listeners = TestUtil.getInternalState(checker, "listeners");
assertWithMessage("Invalid child listener class").that(listeners.get(listeners.size() - 1) instanceof DebugAuditAdapter).isTrue();
}
use of com.puppycrawl.tools.checkstyle.internal.testmodules.DebugAuditAdapter in project checkstyle by checkstyle.
the class CheckerTest method testAddAuditListenerAsChild.
@Test
public void testAddAuditListenerAsChild() throws Exception {
final Checker checker = new Checker();
final DebugAuditAdapter auditAdapter = new DebugAuditAdapter();
final PackageObjectFactory factory = new PackageObjectFactory(new HashSet<>(), Thread.currentThread().getContextClassLoader()) {
@Override
public Object createModule(String name) throws CheckstyleException {
Object adapter = auditAdapter;
if (!name.equals(DebugAuditAdapter.class.getName())) {
adapter = super.createModule(name);
}
return adapter;
}
};
checker.setModuleFactory(factory);
checker.setupChild(createModuleConfig(DebugAuditAdapter.class));
// Let's try fire some events
checker.process(Collections.singletonList(new File("dummy.java")));
assertWithMessage("Checker.fireAuditStarted() doesn't call listener").that(auditAdapter.wasCalled()).isTrue();
}
Aggregations