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.
This commit is contained in:
Lars Kühne 2002-12-05 06:29:51 +00:00
parent 46c634bea2
commit ce9f55c439
2 changed files with 51 additions and 0 deletions

View File

@ -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();

View File

@ -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());
}
}