From ce9f55c439621cd2a130519aea0ca4367bc7c67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20K=C3=BChne?= Date: Thu, 5 Dec 2002 06:29:51 +0000 Subject: [PATCH] make sure that Checker calls the destroy method of FileSetCheck. Clover is really cool, I found this bug by looking at the coverage of AbstractFileSetCheck - clover told me that destroy was never executed and that seemed strange to me. --- .../puppycrawl/tools/checkstyle/Checker.java | 1 + .../checkstyle/FileSetCheckLifecycleTest.java | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/FileSetCheckLifecycleTest.java diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java index 5d2964775..9e821ab2e 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/Checker.java @@ -208,6 +208,7 @@ public class Checker extends AutomaticBean for (int i = 0; i < mFileSetChecks.size(); i++) { FileSetCheck fileSetCheck = (FileSetCheck) mFileSetChecks.get(i); fileSetCheck.process(aFiles); + fileSetCheck.destroy(); } int errorCount = mCounter.getCount(); fireAuditFinished(); diff --git a/src/tests/com/puppycrawl/tools/checkstyle/FileSetCheckLifecycleTest.java b/src/tests/com/puppycrawl/tools/checkstyle/FileSetCheckLifecycleTest.java new file mode 100644 index 000000000..4bd9bc98f --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/FileSetCheckLifecycleTest.java @@ -0,0 +1,50 @@ +package com.puppycrawl.tools.checkstyle; + +import java.io.File; + +import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck; +import com.puppycrawl.tools.checkstyle.api.Configuration; + +public class FileSetCheckLifecycleTest extends BaseCheckTestCase +{ + protected DefaultConfiguration createCheckerConfig(Configuration aCheckConfig) + { + final DefaultConfiguration dc = new DefaultConfiguration("root"); + dc.addChild(aCheckConfig); + return dc; + } + + public static class TestFileSetCheck extends AbstractFileSetCheck + { + private static boolean destroyed = false; + + public void destroy() + { + destroyed = true; + } + + public static boolean isDestroyed() + { + return destroyed; + } + + public void process(File[] aFiles) + { + } + } + + public void testTranslation() + throws Exception + { + Configuration checkConfig = createCheckConfig(TestFileSetCheck.class); + Checker c = createChecker(checkConfig); + final String filepath = getPath("InputScopeAnonInner.java"); + + final String[] expected = { + }; + verify(c, filepath, filepath, expected); + + assertTrue("destroy() not called by Checker", TestFileSetCheck.isDestroyed()); + } + +}