From: David S. <ds...@us...> - 2007-07-02 18:11:20
|
Update of /cvsroot/junit/junit/src/org/junit/experimental/theories/runner/api In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27902/src/org/junit/experimental/theories/runner/api Added Files: Theories.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. --- NEW FILE: Theories.java --- /** * */ package org.junit.experimental.theories.runner.api; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import org.junit.Assert; import org.junit.Assume.AssumptionViolatedException; import org.junit.experimental.theories.javamodel.api.ConcreteFunction; import org.junit.experimental.theories.methods.api.Theory; import org.junit.experimental.theories.runner.TheoryContainerReference; import org.junit.internal.runners.InitializationError; import org.junit.internal.runners.JUnit4ClassRunner; import org.junit.internal.runners.TestClass; import org.junit.internal.runners.TestMethod; @SuppressWarnings("restriction") public class Theories extends JUnit4ClassRunner { public static class TheoryMethod extends TestMethod { private final Method fMethod; private List<AssumptionViolatedException> fInvalidParameters= new ArrayList<AssumptionViolatedException>(); private TheoryMethod(Method method, TestClass testClass) { super(method, testClass); fMethod= method; } @Override public void invoke(Object test) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { TheoryContainerReference container= new TheoryContainerReference( test); ConcreteFunction function= new ConcreteFunction(test, fMethod); int runCount= 0; try { runCount+= container.runWithParameters(this, new ArrayList<Object>(), function.signatures()); } catch (Throwable e) { throw new InvocationTargetException(e); } if (runCount == 0) Assert .fail("Never found parameters that satisfied method. Violated assumptions: " + fInvalidParameters); } public boolean nullsOk() { return fMethod.getAnnotation(Theory.class).nullsAccepted(); } public Method getMethod() { return fMethod; } public void addAssumptionFailure(AssumptionViolatedException e) { fInvalidParameters.add(e); } } @Override protected void validate() throws InitializationError { } public Theories(Class<?> klass) throws InitializationError { super(klass); } @Override protected List<Method> getTestMethods() { List<Method> testMethods= super.getTestMethods(); testMethods.addAll(getTestClass().getAnnotatedMethods(Theory.class)); return testMethods; } @Override protected TestMethod wrapMethod(final Method method) { return new TheoryMethod(method, getTestClass()); } } |