Update of /cvsroot/junit/junit/org/junit/internal/javamodel In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv24081/org/junit/internal/javamodel Modified Files: Tag: saff_r41_runner_refactoring JavaModelElement.java JavaMethod.java JavaMethodList.java WrappedJavaModelElement.java JavaClass.java Log Message: About to work on trunk with Kent Index: JavaModelElement.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/javamodel/Attic/JavaModelElement.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- JavaModelElement.java 18 Oct 2006 20:36:08 -0000 1.1.2.1 +++ JavaModelElement.java 16 Nov 2006 17:52:10 -0000 1.1.2.2 @@ -1,16 +1,27 @@ package org.junit.internal.javamodel; -import org.junit.runner.Description; +import org.junit.internal.runners.JavaTestInterpreter; +import org.junit.runner.Runner; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunNotifier; -public abstract class JavaModelElement { +public abstract class JavaModelElement extends Runner { + // TODO: only construct through interpreter + + private final JavaTestInterpreter fInterpreter; + + public JavaModelElement(JavaTestInterpreter interpreter) { + fInterpreter = interpreter; + } + public abstract String getName(); public void addFailure(RunNotifier runNotifier, Throwable targetException) { runNotifier - .fireTestFailure(new Failure(description(), targetException)); + .fireTestFailure(new Failure(getDescription(), targetException)); + } + + protected JavaTestInterpreter getInterpreter() { + return fInterpreter; } - - protected abstract Description description(); } Index: JavaMethod.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/javamodel/Attic/JavaMethod.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- JavaMethod.java 18 Oct 2006 20:36:08 -0000 1.1.2.1 +++ JavaMethod.java 16 Nov 2006 17:52:10 -0000 1.1.2.2 @@ -19,8 +19,8 @@ import org.junit.Test; import org.junit.Test.None; import org.junit.internal.runners.MethodAnnotation; -import org.junit.internal.runners.TestEnvironment; import org.junit.runner.Description; +import org.junit.runner.notification.RunNotifier; // TODO: check names of various "run" methods @@ -31,6 +31,7 @@ private final JavaClass fJavaClass; public JavaMethod(JavaClass javaClass, Method current) { + super(javaClass.getInterpreter()); fJavaClass= javaClass; fMethod= current; } @@ -79,7 +80,7 @@ // TODO: push out @Override - public Description description() { + public Description getDescription() { return Description.createTestDescription(fJavaClass.getTestClass(), getName()); } @@ -100,59 +101,56 @@ return Before.class; } - public void runWithoutBeforeAndAfter(TestEnvironment environment, - Object test) { + public void runWithoutBeforeAndAfter(RunNotifier notifier, Object test) { // TODO: is this envious of environment? try { - environment.getInterpreter().executeMethodBody(test, this); + getInterpreter().executeMethodBody(test, this); if (expectsException()) - addFailure(environment.getRunNotifier(), new AssertionError( - "Expected exception: " + expectedException().getName())); + addFailure(notifier, new AssertionError("Expected exception: " + + expectedException().getName())); } catch (InvocationTargetException e) { Throwable actual= e.getTargetException(); if (!expectsException()) - addFailure(environment.getRunNotifier(), actual); + addFailure(notifier, actual); else if (isUnexpected(actual)) { String message= "Unexpected exception, expected<" + expectedException().getName() + "> but was<" + actual.getClass().getName() + ">"; - addFailure(environment.getRunNotifier(), new Exception(message, - actual)); + addFailure(notifier, new Exception(message, actual)); } } catch (Throwable e) { // TODO: DUP on environment.getRunNotifier - addFailure(environment.getRunNotifier(), e); + addFailure(notifier, e); } } - void invokeTestMethod(TestEnvironment testEnvironment) { + void invokeTestMethod(RunNotifier notifier) { Object test; try { test= getJavaClass().newInstance(); } catch (Exception e) { - testEnvironment.getRunNotifier().testAborted(description(), e); + notifier.testAborted(getDescription(), e); return; } - run(testEnvironment, test); + run(notifier, test); } - void runWithoutTimeout(final Object test, - final TestEnvironment testEnvironment) { + void runWithoutTimeout(final Object test, final RunNotifier notifier) { // TODO: is this envious now? Yes runWithBeforeAndAfter(new Runnable() { public void run() { - runWithoutBeforeAndAfter(testEnvironment, test); + runWithoutBeforeAndAfter(notifier, test); } - }, test, testEnvironment.getRunNotifier()); + }, test, notifier); // TODO: ugly } void runWiteTimeout(long timeout, final Object test, - final TestEnvironment testEnvironment) { + final RunNotifier notifier) { ExecutorService service= Executors.newSingleThreadExecutor(); Callable<Object> callable= new Callable<Object>() { public Object call() throws Exception { - runWithoutTimeout(test, testEnvironment); + runWithoutTimeout(test, notifier); return null; } }; @@ -167,28 +165,33 @@ // if one occurred // during the invocation } catch (TimeoutException e) { - addFailure(testEnvironment.getRunNotifier(), new Exception(String - .format("test timed out after %d milliseconds", timeout))); + addFailure(notifier, new Exception(String.format( + "test timed out after %d milliseconds", timeout))); } catch (Exception e) { // TODO: DUP - addFailure(testEnvironment.getRunNotifier(), e); + addFailure(notifier, e); } } - void run(TestEnvironment environment, Object test) { + void run(RunNotifier notifier, Object test) { if (isIgnored()) { - environment.getRunNotifier().fireTestIgnored(description()); + notifier.fireTestIgnored(getDescription()); return; } - environment.getRunNotifier().fireTestStarted(description()); + notifier.fireTestStarted(getDescription()); try { long timeout= getTimeout(); if (timeout > 0) - runWiteTimeout(timeout, test, environment); + runWiteTimeout(timeout, test, notifier); else - runWithoutTimeout(test, environment); + runWithoutTimeout(test, notifier); } finally { - environment.getRunNotifier().fireTestFinished(description()); + notifier.fireTestFinished(getDescription()); } } + + @Override + public void run(RunNotifier notifier) { + invokeTestMethod(notifier); + } } \ No newline at end of file Index: JavaMethodList.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/javamodel/Attic/JavaMethodList.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- JavaMethodList.java 18 Oct 2006 20:36:08 -0000 1.1.2.1 +++ JavaMethodList.java 16 Nov 2006 17:52:10 -0000 1.1.2.2 @@ -6,14 +6,16 @@ import java.util.Iterator; import java.util.List; -import org.junit.internal.runners.TestEnvironment; import org.junit.runner.Description; import org.junit.runner.manipulation.Filter; +import org.junit.runner.manipulation.Filterable; import org.junit.runner.manipulation.NoTestsRemainException; +import org.junit.runner.manipulation.Sortable; import org.junit.runner.manipulation.Sorter; +import org.junit.runner.notification.RunNotifier; public class JavaMethodList extends JavaModelElement implements - Iterable<JavaMethod> { + Iterable<JavaMethod>, Filterable, Sortable { private static final long serialVersionUID= 1L; private final JavaClass fJavaClass; @@ -21,23 +23,24 @@ private List<JavaMethod> fMethods= new ArrayList<JavaMethod>(); public JavaMethodList(JavaClass javaClass) { + super(javaClass.getInterpreter()); fJavaClass= javaClass; } public void filter(Filter filter) throws NoTestsRemainException { for (Iterator<JavaMethod> iter= fMethods.iterator(); iter.hasNext();) { JavaMethod method= iter.next(); - if (!filter.shouldRun(method.description())) + if (!filter.shouldRun(method.getDescription())) iter.remove(); } if (fMethods.isEmpty()) throw new NoTestsRemainException(); } - public void filter(final Sorter sorter) { + public void sort(final Sorter sorter) { Collections.sort(fMethods, new Comparator<JavaMethod>() { public int compare(JavaMethod o1, JavaMethod o2) { - return sorter.compare(o1.description(), o2.description()); + return sorter.compare(o1.getDescription(), o2.getDescription()); } }); } @@ -64,21 +67,22 @@ } @Override - public Description description() { + public Description getDescription() { Description spec= Description.createSuiteDescription(fJavaClass .getName()); for (JavaMethod method : this) - spec.addChild(method.description()); + spec.addChild(method.getDescription()); return spec; } - public void run(TestEnvironment environment) { + @Override + public void run(RunNotifier notifier) { if (isEmpty()) // TODO: DUP - environment.getRunNotifier().testAborted(description(), new Exception( + notifier.testAborted(getDescription(), new Exception( "No runnable methods")); for (JavaMethod method : this) { - method.invokeTestMethod(environment); + method.invokeTestMethod(notifier); } } } Index: WrappedJavaModelElement.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/javamodel/Attic/WrappedJavaModelElement.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- WrappedJavaModelElement.java 18 Oct 2006 20:36:08 -0000 1.1.2.1 +++ WrappedJavaModelElement.java 16 Nov 2006 17:52:10 -0000 1.1.2.2 @@ -5,18 +5,23 @@ import java.util.List; import org.junit.internal.runners.FailedBefore; +import org.junit.internal.runners.JavaTestInterpreter; import org.junit.runner.notification.RunNotifier; public abstract class WrappedJavaModelElement extends JavaModelElement { + public WrappedJavaModelElement(JavaTestInterpreter interpreter) { + super(interpreter); + } + public abstract Class<? extends Annotation> getBeforeAnnotation(); - + public abstract Class<? extends Annotation> getAfterAnnotation(); - + public abstract JavaClass getJavaClass(); + void runAfters(Object test, RunNotifier runNotifier) { // TODO: train wreck - for (Method after : getJavaClass().getMethods( - getAfterAnnotation())) { + for (Method after : getJavaClass().getMethods(getAfterAnnotation())) { try { after.invoke(test); } catch (Throwable e) { @@ -25,12 +30,11 @@ } } - void runBefores(Object test, RunNotifier runNotifier) - throws FailedBefore { + void runBefores(Object test, RunNotifier runNotifier) throws FailedBefore { try { List<Method> befores= getJavaClass().getMethods( getBeforeAnnotation()); - + // TODO: no auto-correct if wrong type on left side of new-style // for? for (Method before : befores) @@ -41,7 +45,8 @@ } } - public void runWithBeforeAndAfter(Runnable protectThis, Object test, RunNotifier runNotifier) { + public void runWithBeforeAndAfter(Runnable protectThis, Object test, + RunNotifier runNotifier) { try { runBefores(test, runNotifier); protectThis.run(); Index: JavaClass.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/javamodel/Attic/JavaClass.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- JavaClass.java 18 Oct 2006 20:36:08 -0000 1.1.2.1 +++ JavaClass.java 16 Nov 2006 17:52:10 -0000 1.1.2.2 @@ -16,12 +16,14 @@ import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.MethodAnnotation; import org.junit.runner.Description; +import org.junit.runner.notification.RunNotifier; public class JavaClass extends WrappedJavaModelElement { // TODO: push out private final Class<?> fClass; - public JavaClass(Class<?> type) { + public JavaClass(Class<?> type, JavaTestInterpreter interpreter) { + super(interpreter); fClass= type; } @@ -32,7 +34,7 @@ // TODO: this will not add parameterized superclasses (need to use // interpreter here?) if (fClass.getSuperclass() != null) - results.addAll(new JavaClass(fClass.getSuperclass()) + results.addAll(getInterpreter().buildClass(fClass.getSuperclass()) .getSuperClasses()); return results; } @@ -131,7 +133,13 @@ } @Override - protected Description description() { + public Description getDescription() { return Description.createSuiteDescription(fClass); } + + @Override + public void run(RunNotifier notifier) { + // TODO Auto-generated method stub + + } } \ No newline at end of file |