Search in sources :

Example 6 with DebugAuditAdapter

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();
}
Also used : Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) DebugAuditAdapter(com.puppycrawl.tools.checkstyle.internal.testmodules.DebugAuditAdapter) AuditListener(com.puppycrawl.tools.checkstyle.api.AuditListener) Test(org.junit.jupiter.api.Test)

Example 7 with DebugAuditAdapter

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();
}
Also used : DebugAuditAdapter(com.puppycrawl.tools.checkstyle.internal.testmodules.DebugAuditAdapter) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

DebugAuditAdapter (com.puppycrawl.tools.checkstyle.internal.testmodules.DebugAuditAdapter)7 Test (org.junit.jupiter.api.Test)7 File (java.io.File)4 Violation (com.puppycrawl.tools.checkstyle.api.Violation)3 TreeSet (java.util.TreeSet)3 ArrayList (java.util.ArrayList)2 AuditListener (com.puppycrawl.tools.checkstyle.api.AuditListener)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 DebugFilter (com.puppycrawl.tools.checkstyle.internal.testmodules.DebugFilter)1 TestBeforeExecutionFileFilter (com.puppycrawl.tools.checkstyle.internal.testmodules.TestBeforeExecutionFileFilter)1 TestFileSetCheck (com.puppycrawl.tools.checkstyle.internal.testmodules.TestFileSetCheck)1