01: package net.sf.clirr.core.internal.checks;
02:
03: import junit.framework.TestCase;
04: import net.sf.clirr.core.Checker;
05: import net.sf.clirr.core.ClassSelector;
06: import net.sf.clirr.core.ApiDifference;
07: import net.sf.clirr.core.CheckerFactory;
08: import net.sf.clirr.core.ClassFilter;
09: import net.sf.clirr.core.internal.ClassChangeCheck;
10: import net.sf.clirr.core.internal.bcel.BcelTypeArrayBuilder;
11: import net.sf.clirr.core.spi.JavaType;
12:
13: import org.apache.bcel.util.ClassSet;
14:
15: import java.io.File;
16: import java.net.URL;
17: import java.net.URLClassLoader;
18:
19: /**
20: * Abstract Baseclass to test individual Checks.
21: * @author lkuehne
22: */
23: public abstract class AbstractCheckTestCase extends TestCase {
24: protected final File getTestInputDir() {
25: // property is set in project.properties
26: return new File(System.getProperty("testinput"));
27: }
28:
29: protected void verify(Checker checker, ClassSet baseline,
30: ClassSet current, ApiDifference[] expected) {
31: }
32:
33: protected File[] getBaseLine() {
34: return new File[] { new File(getTestInputDir(),
35: "testlib-v1.jar") };
36: }
37:
38: protected File[] getCurrent() {
39: return new File[] { new File(getTestInputDir(),
40: "testlib-v2.jar") };
41: }
42:
43: protected void verify(ExpectedDiff[] expected) throws Exception {
44: TestDiffListener tdl = new TestDiffListener();
45: Checker checker = CheckerFactory
46: .createChecker(createCheck(tdl));
47: ClassFilter classSelector = createClassSelector();
48:
49: final JavaType[] origClasses = BcelTypeArrayBuilder
50: .createClassSet(getBaseLine(), new URLClassLoader(
51: new URL[] {}), classSelector);
52:
53: final JavaType[] newClasses = BcelTypeArrayBuilder
54: .createClassSet(getCurrent(), new URLClassLoader(
55: new URL[] {}), classSelector);
56:
57: checker.reportDiffs(origClasses, newClasses);
58:
59: tdl.checkExpected(expected);
60: }
61:
62: /**
63: * Creates an object which selects the appropriate classes from the
64: * test jars for this test.
65: * <p>
66: * This base implementation returns a selector which selects all classes
67: * in the base "testlib" package (but no sub-packages). Tests which wish
68: * to select different classes from the test jars should override this
69: * method.
70: */
71: protected ClassFilter createClassSelector() {
72: // only check classes in the base "testlib" package of the jars
73: ClassSelector classSelector = new ClassSelector(
74: ClassSelector.MODE_IF);
75: classSelector.addPackage("testlib");
76: return classSelector;
77: }
78:
79: /**
80: * Creates a check and sets it up so ApiDifferences are reported to the test diff listener.
81: *
82: * @param tdl the test diff listener that records the recognized api changes.
83: * @return the confiured check
84: */
85: protected abstract ClassChangeCheck createCheck(TestDiffListener tdl);
86: }
|