From: David S. <ds...@us...> - 2007-07-02 18:11:11
|
Update of /cvsroot/junit/junit/src/org/junit/experimental/theories/javamodel/api In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27902/src/org/junit/experimental/theories/javamodel/api Added Files: ConcreteFunction.java Function.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: ConcreteFunction.java --- /** * */ package org.junit.experimental.theories.javamodel.api; import java.lang.reflect.Method; public class ConcreteFunction extends Function { protected final Object target; protected final Method method; public ConcreteFunction(Object target, Method method) { this.target = target; this.method = method; } @Override public Object getTarget() { return target; } @Override public Method getMethod() { return method; } @Override public boolean equals(Object obj) { Function function = (Function) obj; return targetIs(function.getTarget()) && method.equals(function.getMethod()); } private boolean targetIs(Object otherTarget) { if (target == null) return otherTarget == null; return target.equals(otherTarget); } @Override public String toString() { return String.format("%s.%s", target, method); } } --- NEW FILE: Function.java --- package org.junit.experimental.theories.javamodel.api; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Arrays; import org.junit.experimental.theories.methods.api.ParameterSignature; public abstract class Function { public abstract Method getMethod(); public abstract Object getTarget(); public Object invoke(Object... paramArray) throws Throwable { getMethod().setAccessible(true); Object[] modParams = modifyParameters(paramArray); if (modParams.length != parameterTypes().length) throw new IllegalArgumentException(String.format( "Wrong number of parameters, passing %s to %s", Arrays .asList(modParams), getMethod())); try { return getMethod().invoke(getTarget(), modParams); } catch (InvocationTargetException e) { throw e.getTargetException(); } } public Throwable exceptionThrown(Object... paramArray) { try { invoke(paramArray); } catch(Throwable t) { return t; } return null; } protected Object[] modifyParameters(Object... paramArray) { return paramArray; } public Type[] parameterTypes() { return getMethod().getGenericParameterTypes(); } public Object[] emptyParameterArray() { return new Object[parameterTypes().length]; } public Function curryWith(final Object[] curriedParameters) { return new Function() { @Override public Method getMethod() { return Function.this.getMethod(); } @Override public Object getTarget() { return Function.this.getTarget(); } @Override protected Object[] modifyParameters(Object... paramArray) { ArrayList<Object> list = new ArrayList<Object>(); list.addAll(Arrays.asList(curriedParameters)); list.addAll(Arrays.asList(paramArray)); return list.toArray(); } }; } public ArrayList<ParameterSignature> signatures() { return ParameterSignature.signatures(getMethod()); } } |