Search in sources :

Example 1 with TestFileSetCheck

use of com.puppycrawl.tools.checkstyle.internal.testmodules.TestFileSetCheck 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)

Aggregations

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 TestBeforeExecutionFileFilter (com.puppycrawl.tools.checkstyle.internal.testmodules.TestBeforeExecutionFileFilter)1 TestFileSetCheck (com.puppycrawl.tools.checkstyle.internal.testmodules.TestFileSetCheck)1 File (java.io.File)1 TreeSet (java.util.TreeSet)1 Test (org.junit.jupiter.api.Test)1