From: David S. <ds...@us...> - 2006-10-17 19:08:12
|
Update of /cvsroot/junit/junit/org/junit/internal/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv18958/org/junit/internal/runners Modified Files: Tag: saff_r41_runner_refactoring TestMethodRunner.java Log Message: Remove TestIntrospector, introduce PerTestNotifier Index: TestMethodRunner.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/TestMethodRunner.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -d -r1.2 -r1.2.2.1 --- TestMethodRunner.java 15 Feb 2006 22:55:28 -0000 1.2 +++ TestMethodRunner.java 17 Oct 2006 19:08:09 -0000 1.2.2.1 @@ -1,7 +1,5 @@ package org.junit.internal.runners; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -13,38 +11,38 @@ import org.junit.Before; import org.junit.runner.Description; import org.junit.runner.notification.RunNotifier; -import org.junit.runner.notification.Failure; public class TestMethodRunner extends BeforeAndAfterRunner { private final Object fTest; - private final Method fMethod; - private final RunNotifier fNotifier; - private final TestIntrospector fTestIntrospector; - private final Description fDescription; - public TestMethodRunner(Object test, Method method, RunNotifier notifier, Description description) { - super(test.getClass(), Before.class, After.class, test); + private final JavaMethod fJavaMethod; + + private final JavaTestInterpreter fInterpreter; + + public TestMethodRunner(Object test, JavaMethod method, + RunNotifier notifier, Description description, + JavaTestInterpreter interpreter) { + super(test.getClass(), Before.class, After.class, test, + new PerTestNotifier(notifier, description)); fTest= test; - fMethod= method; - fNotifier= notifier; - fTestIntrospector= new TestIntrospector(test.getClass()); - fDescription= description; + fJavaMethod= method; + fInterpreter= interpreter; } public void run() { - if (fTestIntrospector.isIgnored(fMethod)) { - fNotifier.fireTestIgnored(fDescription); + if (fJavaMethod.isIgnored()) { + fPerTestNotifier.fireTestIgnored(); return; } - fNotifier.fireTestStarted(fDescription); + fPerTestNotifier.fireTestStarted(); try { - long timeout= fTestIntrospector.getTimeout(fMethod); + long timeout= fJavaMethod.getTimeout(); if (timeout > 0) runWithTimeout(timeout); else runMethod(); } finally { - fNotifier.fireTestFinished(fDescription); + fPerTestNotifier.fireTestFinished(); } } @@ -63,57 +61,23 @@ TimeUnit.MILLISECONDS); if (!terminated) service.shutdownNow(); - result.get(timeout, TimeUnit.MILLISECONDS); // throws the exception if one occurred during the invocation + result.get(timeout, TimeUnit.MILLISECONDS); // throws the exception + // if one occurred + // during the invocation } catch (TimeoutException e) { - addFailure(new Exception(String.format("test timed out after %d milliseconds", timeout))); + fPerTestNotifier.addFailure(new Exception(String.format( + "test timed out after %d milliseconds", timeout))); } catch (Exception e) { - addFailure(e); - } - } - - private void runMethod() { - runProtected(); - } - - @Override - protected void runUnprotected() { - try { - executeMethodBody(); - if (expectsException()) - addFailure(new AssertionError("Expected exception: " + expectedException().getName())); - } catch (InvocationTargetException e) { - Throwable actual= e.getTargetException(); - if (!expectsException()) - addFailure(actual); - else if (isUnexpected(actual)) { - String message= "Unexpected exception, expected<" + expectedException().getName() + "> but was<" - + actual.getClass().getName() + ">"; - addFailure(new Exception(message, actual)); - } - } catch (Throwable e) { - addFailure(e); + fPerTestNotifier.addFailure(e); } } - protected void executeMethodBody() throws IllegalAccessException, InvocationTargetException { - fMethod.invoke(fTest); + private void runMethod() { + runProtected(); } @Override - protected void addFailure(Throwable e) { - fNotifier.fireTestFailure(new Failure(fDescription, e)); - } - - private boolean expectsException() { - return expectedException() != null; - } - - private Class<? extends Throwable> expectedException() { - return fTestIntrospector.expectedException(fMethod); - } - - private boolean isUnexpected(Throwable exception) { - return ! expectedException().isAssignableFrom(exception.getClass()); + protected void runUnprotected() { + fJavaMethod.runUnprotected(fInterpreter, fTest, fPerTestNotifier); } } - |