package net.sf.clirr.checks;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;

import junit.framework.TestCase;
import net.sf.clirr.Checker;
import net.sf.clirr.CheckerFactory;
import net.sf.clirr.event.ApiDifference;
import net.sf.clirr.framework.ClassChangeCheck;
import org.apache.bcel.util.ClassSet;

/**
 * Abstract Baseclass to test individual Checks.
 * @author lkuehne
 */
public abstract class AbstractCheckTestCase extends TestCase
{
    protected final File getTestInputDir()
    {
        // property is set in project.properties
        return new File(System.getProperty("testinput"));
    }

    protected void verify(
            Checker checker,
            ClassSet baseline, ClassSet current,
            ApiDifference[] expected)
    {
    }

    protected File[] getBaseLine()
    {
        return new File[]{
            new File(getTestInputDir(), "testlib-v1.jar")
        };
    }

    protected File[] getCurrent()
    {
        return new File[]{
            new File(getTestInputDir(), "testlib-v2.jar")
        };
    }

    protected void verify(ApiDifference[] expected)
    {
        TestDiffListener tdl = new TestDiffListener();
        Checker checker = CheckerFactory.createChecker(createCheck(tdl));
        checker.reportDiffs(getBaseLine(), getCurrent(), new URLClassLoader(new URL[]{}), new URLClassLoader(new URL[]{}));
        tdl.checkExpected(expected);
    }

    /**
     * Creates a check and sets it up so ApiDifferences are reported to the test diff listener.
     *
     * @param tdl the test diff listener that records the recognized api changes.
     * @return the confiured check
     */
    protected abstract ClassChangeCheck createCheck(TestDiffListener tdl);
}

@@ -285,16 +285,61 @@
 eCheck;%0A
+import net.sf.clirr.framework.ClassSelector;%0A
 import o
@@ -368,16 +368,16 @@
 assSet;%0A
-
 %0A/**%0A * 
@@ -1297,24 +1297,86 @@
 heck(tdl));%0A
+        ClassSelector classSelector = createClassSelector();%0A%0A
         chec
@@ -1391,16 +1391,29 @@
 rtDiffs(
+%0A            
 getBaseL
@@ -1433,16 +1433,29 @@
 rent(), 
+%0A            
 new URLC
@@ -1479,16 +1479,29 @@
 L%5B%5D%7B%7D), 
+%0A            
 new URLC
@@ -1527,46 +1527,751 @@
 %5D%7B%7D)
-);%0A        tdl.checkExpected(expected)
+,%0A            classSelector);%0A            %0A        tdl.checkExpected(expected);%0A    %7D%0A%0A    /**%0A     * Creates an object which selects the appropriate classes from the%0A     * test jars for this test.%0A     * %3Cp%3E%0A     * This base implementation returns a selector which selects all classes%0A     * in the base %22testlib%22 package (but no sub-packages). Tests which wish%0A     * to select different classes from the test jars should override this%0A     * method.%0A     */%0A    protected ClassSelector createClassSelector()%0A    %7B%0A        // only check classes in the base %22testlib%22 package of the jars%0A        ClassSelector classSelector = new ClassSelector(ClassSelector.MODE_IF);%0A        classSelector.addPackage(%22testlib%22);%0A        return classSelector
 ;%0A  

use class selector to make unit tests more robust contributed by Simon Kitching