From: David S. <ds...@us...> - 2007-07-02 18:11:32
|
Update of /cvsroot/junit/junit/src/org/junit/internal/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27902/src/org/junit/internal/runners Modified Files: MethodRoadie.java JUnit4ClassRunner.java TestMethod.java Log Message: - The hamcrest-core-1.1 library is now included in the JUnit distribution. For more hamcrest matchers, see the hamcrest-library jar from http://code.google.com/p/hamcrest - The Popper Theory runner (http://popper.tigris.org) has been absorbed into the JUnit project, under the package name org.junit.experimental.theories - Several additional libraries used in the theories tests have been added in a new testlib directory - New "assertThat" statement to work with hamcrest matchers: // same as assertEquals(3, x) assertThat(x, is(3)); // same as assertNull(y) assertThat(y, nullValue()); - New feature: assumeThat. A failed assumption will cause the test to pass, without further execution. (The behavior of assumeThat may change in the future to allow richer reporting of tests that are skipped because of failed assumptions) // pass on any non-Windows system @Test public void getRootDrive() { assumeThat(getOsString(), is("Windows")); getFile("C:\"); // ... } - Convenience assumption functions: // none of these are null assumeNotNull(a, b, c); assumeTrue(everythingOk()); try { getDatabaseConnection(); } catch (Exception e) { assumeNoException(e); } - Documentation fixed for many assertEquals array methods - Two bugs in numeric equality fixed: 1718905: assertEquals does not compare float correctly 1715326: assertEquals does not compare java.math.BigDecimal properly - The protocol for overriding JUnit4ClassRunner has changed again. Please see the source for details. - Extenders can now extend TestMethod to describe the behavior of running methods that do not have a @Test annotation. - Adding Annotations to Description caused a binary compatibility problem with clients compiled on previous JUnit versions. This has been fixed. Index: MethodRoadie.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/internal/runners/MethodRoadie.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- MethodRoadie.java 20 Mar 2007 14:43:50 -0000 1.1 +++ MethodRoadie.java 2 Jul 2007 18:10:58 -0000 1.2 @@ -10,23 +10,22 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import org.junit.Assume.AssumptionViolatedException; import org.junit.runner.Description; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunNotifier; public class MethodRoadie { private final Object fTest; - private final Method fMethod; private final RunNotifier fNotifier; private final Description fDescription; private TestMethod fTestMethod; - public MethodRoadie(Object test, Method method, RunNotifier notifier, Description description, TestClass testClass) { + public MethodRoadie(Object test, TestMethod method, RunNotifier notifier, Description description) { fTest= test; - fMethod= method; fNotifier= notifier; fDescription= description; - fTestMethod= new TestMethod(method, testClass); + fTestMethod= method; } public void run() { @@ -81,12 +80,14 @@ protected void runTestMethod() { try { - fMethod.invoke(fTest); + fTestMethod.invoke(fTest); if (fTestMethod.expectsException()) addFailure(new AssertionError("Expected exception: " + fTestMethod.getExpectedException().getName())); } catch (InvocationTargetException e) { Throwable actual= e.getTargetException(); - if (!fTestMethod.expectsException()) + if (actual instanceof AssumptionViolatedException) + return; + else if (!fTestMethod.expectsException()) addFailure(actual); else if (fTestMethod.isUnexpected(actual)) { String message= "Unexpected exception, expected<" + fTestMethod.getExpectedException().getName() + "> but was<" Index: JUnit4ClassRunner.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/internal/runners/JUnit4ClassRunner.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- JUnit4ClassRunner.java 26 Apr 2007 19:56:31 -0000 1.2 +++ JUnit4ClassRunner.java 2 Jul 2007 18:10:58 -0000 1.3 @@ -23,10 +23,14 @@ public JUnit4ClassRunner(Class<?> klass) throws InitializationError { fTestClass= new TestClass(klass); - fTestMethods= fTestClass.getTestMethods(); + fTestMethods= getTestMethods(); validate(); } + protected List<Method> getTestMethods() { + return fTestClass.getTestMethods(); + } + protected void validate() throws InitializationError { MethodValidator methodValidator= new MethodValidator(fTestClass); methodValidator.validateMethodsForDefaultRunner(); @@ -69,21 +73,23 @@ } protected void invokeTestMethod(Method method, RunNotifier notifier) { + Description description= methodDescription(method); Object test; try { test= createTest(); } catch (InvocationTargetException e) { - notifier.testAborted(methodDescription(method), e.getCause()); + notifier.testAborted(description, e.getCause()); return; } catch (Exception e) { - notifier.testAborted(methodDescription(method), e); + notifier.testAborted(description, e); return; } - createMethodRunner(test, method, notifier).run(); + TestMethod testMethod= wrapMethod(method); + new MethodRoadie(test, testMethod, notifier, description).run(); } - protected MethodRoadie createMethodRunner(Object test, Method method, RunNotifier notifier) { - return new MethodRoadie(test, method, notifier, methodDescription(method), fTestClass); + protected TestMethod wrapMethod(Method method) { + return new TestMethod(method, fTestClass); } protected String testName(Method method) { @@ -91,8 +97,7 @@ } protected Description methodDescription(Method method) { - Description result= Description.createTestDescription(getTestClass().getJavaClass(), testName(method), testAnnotations(method)); - return result; + return Description.createTestDescription(getTestClass().getJavaClass(), testName(method), testAnnotations(method)); } protected Annotation[] testAnnotations(Method method) { Index: TestMethod.java =================================================================== RCS file: /cvsroot/junit/junit/src/org/junit/internal/runners/TestMethod.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- TestMethod.java 20 Mar 2007 14:43:50 -0000 1.3 +++ TestMethod.java 2 Jul 2007 18:10:58 -0000 1.4 @@ -1,5 +1,6 @@ package org.junit.internal.runners; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.List; @@ -10,7 +11,6 @@ import org.junit.Test.None; public class TestMethod { - private final Method fMethod; private TestClass fTestClass; @@ -25,13 +25,15 @@ public long getTimeout() { Test annotation= fMethod.getAnnotation(Test.class); + if (annotation == null) + return 0; long timeout= annotation.timeout(); return timeout; } - Class<? extends Throwable> getExpectedException() { + protected Class<? extends Throwable> getExpectedException() { Test annotation= fMethod.getAnnotation(Test.class); - if (annotation.expected() == None.class) + if (annotation == null || annotation.expected() == None.class) return null; else return annotation.expected(); @@ -53,4 +55,8 @@ return fTestClass.getAnnotatedMethods(After.class); } + public void invoke(Object test) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { + fMethod.invoke(test); + } + } |