From: David S. <ds...@us...> - 2006-10-17 19:03:56
|
Update of /cvsroot/junit/junit/org/junit/internal/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv16932/org/junit/internal/runners Modified Files: Tag: saff_r41_runner_refactoring BeforeAndAfterRunner.java Added Files: Tag: saff_r41_runner_refactoring PerTestNotifier.java Removed Files: Tag: saff_r41_runner_refactoring TestIntrospector.java Log Message: Remove TestIntrospector, introduce PerTestNotifier --- NEW FILE: PerTestNotifier.java --- package org.junit.internal.runners; import org.junit.runner.Description; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunNotifier; public class PerTestNotifier { // TODO: push out private final RunNotifier fNotifier; private final Description fDescription; public PerTestNotifier(RunNotifier notifier, Description description) { fNotifier= notifier; fDescription= description; } public void addFailure(Throwable targetException) { fNotifier.fireTestFailure(new Failure(fDescription, targetException)); } public void fireTestIgnored() { fNotifier.fireTestIgnored(fDescription); } public void fireTestFinished() { fNotifier.fireTestFinished(fDescription); } public void fireTestStarted() { fNotifier.fireTestStarted(fDescription); } } Index: BeforeAndAfterRunner.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/BeforeAndAfterRunner.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -d -r1.2 -r1.2.2.1 --- BeforeAndAfterRunner.java 15 Feb 2006 22:55:28 -0000 1.2 +++ BeforeAndAfterRunner.java 17 Oct 2006 19:03:52 -0000 1.2.2.1 @@ -2,7 +2,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.List; public abstract class BeforeAndAfterRunner { @@ -14,18 +13,21 @@ private final Class<? extends Annotation> fAfterAnnotation; - private TestIntrospector fTestIntrospector; - private Object fTest; + private final JavaClass fJavaClass; + + protected PerTestNotifier fPerTestNotifier; + public BeforeAndAfterRunner(Class<?> testClass, Class<? extends Annotation> beforeAnnotation, - Class<? extends Annotation> afterAnnotation, - Object test) { + Class<? extends Annotation> afterAnnotation, Object test, + PerTestNotifier perTestNotifier) { fBeforeAnnotation= beforeAnnotation; fAfterAnnotation= afterAnnotation; - fTestIntrospector= new TestIntrospector(testClass); fTest= test; + fPerTestNotifier= perTestNotifier; + fJavaClass= new JavaClass(testClass); } public void runProtected() { @@ -40,37 +42,36 @@ protected abstract void runUnprotected(); - protected abstract void addFailure(Throwable targetException); - // Stop after first failed @Before private void runBefores() throws FailedBefore { try { - List<Method> befores= fTestIntrospector.getTestMethods(fBeforeAnnotation); - for (Method before : befores) - invokeMethod(before); + List<JavaMethod> befores= fJavaClass + .getTestMethods(fBeforeAnnotation); + + // TODO: no auto-correct if wrong type on left side of new-style + // for? + for (JavaMethod before : befores) + before.invoke(fTest); } catch (InvocationTargetException e) { - addFailure(e.getTargetException()); + fPerTestNotifier.addFailure(e.getTargetException()); throw new FailedBefore(); } catch (Throwable e) { - addFailure(e); + fPerTestNotifier.addFailure(e); throw new FailedBefore(); } } // Try to run all @Afters regardless private void runAfters() { - List<Method> afters= fTestIntrospector.getTestMethods(fAfterAnnotation); - for (Method after : afters) + List<JavaMethod> afters= fJavaClass.getTestMethods(fAfterAnnotation); + for (JavaMethod after : afters) try { - invokeMethod(after); + after.invoke(fTest); } catch (InvocationTargetException e) { - addFailure(e.getTargetException()); + fPerTestNotifier.addFailure(e.getTargetException()); } catch (Throwable e) { - addFailure(e); // Untested, but seems impossible + fPerTestNotifier.addFailure(e); // Untested, but seems + // impossible } } - - private void invokeMethod(Method method) throws Exception { - method.invoke(fTest); - } } --- TestIntrospector.java DELETED --- |