CVS: junit/src/org/junit/experimental/theories/methods/api Theory.java, NONE, 1.1 DataPoint.java, NONE, 1.1 TestedOn.java, NONE, 1.1 ParameterSupplier.java, NONE, 1.1 ParametersSuppliedBy.java, NONE, 1.1 TestedOnSupplier.java, NONE, 1.1 ParameterSignature.java, NONE, 1.1

David Saff <[email protected]> Mon, 02 Jul 2007 11:11:03 -0700
Newsgroups gmane.comp.java.junit.devel
Message-ID <[email protected]>
Update of /cvsroot/junit/junit/src/org/junit/experimental/theories/methods/api
In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27902/src/org/junit/experimental/theories/methods/api

Added Files:
	Theory.java DataPoint.java TestedOn.java 
	ParameterSupplier.java ParametersSuppliedBy.java 
	TestedOnSupplier.java ParameterSignature.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: Theory.java ---
/**
 * 
 */
package org.junit.experimental.theories.methods.api;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Theory {
	boolean nullsAccepted() default true;
}
--- NEW FILE: DataPoint.java ---
package org.junit.experimental.theories.methods.api;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface DataPoint {

}

--- NEW FILE: TestedOn.java ---
package org.junit.experimental.theories.methods.api;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;


@ParametersSuppliedBy(TestedOnSupplier.class)
@Retention(RetentionPolicy.RUNTIME)
public @interface TestedOn {
	int[] ints();
}

--- NEW FILE: ParameterSupplier.java ---
package org.junit.experimental.theories.methods.api;

import java.util.List;



public abstract class ParameterSupplier {
	public abstract List<?> getValues(Object test, ParameterSignature sig);
}

--- NEW FILE: ParametersSuppliedBy.java ---
package org.junit.experimental.theories.methods.api;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;


@Retention(RetentionPolicy.RUNTIME)
public @interface ParametersSuppliedBy {

	Class<? extends ParameterSupplier> value();

}

--- NEW FILE: TestedOnSupplier.java ---
package org.junit.experimental.theories.methods.api;

import java.util.ArrayList;
import java.util.List;


public class TestedOnSupplier extends ParameterSupplier {
	@Override public List<Object> getValues(Object test, ParameterSignature sig) {
		ArrayList<Object> list = new ArrayList<Object>();
		TestedOn testedOn = (TestedOn) sig.getSupplierAnnotation();
		int[] ints = testedOn.ints();
		for (int i : ints) {
			list.add(i);
		}
		return list;
	}
}

--- NEW FILE: ParameterSignature.java ---
/**
 * 
 */
package org.junit.experimental.theories.methods.api;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;

public class ParameterSignature {
	public static ArrayList<ParameterSignature> signatures(Method method) {
		ArrayList<ParameterSignature> sigs = new ArrayList<ParameterSignature>();
		for (int i = 0; i < method.getParameterTypes().length; i++) {
			sigs.add(new ParameterSignature(method.getParameterTypes()[i],
					method.getParameterAnnotations()[i]));
		}
		return sigs;
	}

	private final Class<?> type;
	private final Annotation[] annotations;

	private ParameterSignature(Class<?> type, Annotation[] annotations) {
		this.type = type;
		this.annotations = annotations;
	}

	public Annotation getSupplierAnnotation() {
		for (Annotation annotation : annotations) {
			if (getSupplier(annotation) != null)
				return annotation;
		}

		return null;
	}

	public ParametersSuppliedBy getSupplier(Annotation annotation) {
		return annotation.annotationType().getAnnotation(
				ParametersSuppliedBy.class);
	}

	public boolean canAcceptField(Field field) {
		return type.isAssignableFrom(field.getType());
	}

	public boolean canAcceptMethod(Method method) {
		return method.isAnnotationPresent(DataPoint.class)
				&& type.isAssignableFrom(method.getReturnType());
	}
}

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/