Search in sources :

Example 1 with TestBeforeExecutionFileFilter

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

Example 2 with TestBeforeExecutionFileFilter

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

Example 3 with TestBeforeExecutionFileFilter

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

Example 4 with TestBeforeExecutionFileFilter

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

Aggregations

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