CVS: junit/src/org/junit/runner Description.java, 1.2, 1.3

David Saff <[email protected]> Thu, 26 Apr 2007 12:56:34 -0700
Newsgroups gmane.comp.java.junit.devel
Message-ID <[email protected]>
Update of /cvsroot/junit/junit/src/org/junit/runner
In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv1805/src/org/junit/runner

Modified Files:
	Description.java 
Log Message:
[Junit-trackers] [ junit-Bugs-1684562 ] assertEquals throws NPE while comparing null elements 
Descriptions now have Annotations

Index: Description.java
===================================================================
RCS file: /cvsroot/junit/junit/src/org/junit/runner/Description.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Description.java	21 Feb 2007 14:44:00 -0000	1.2
+++ Description.java	26 Apr 2007 19:56:31 -0000	1.3
@@ -1,6 +1,9 @@
 package org.junit.runner;
 
+import java.lang.annotation.Annotation;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
 
 /**
  * <p>A <code>Description</code> describes a test which is to be run or has been run. <code>Descriptions</code> 
@@ -25,10 +28,11 @@
 	 * Create a <code>Description</code> named <code>name</code>.
 	 * Generally, you will add children to this <code>Description</code>.
 	 * @param name the name of the <code>Description</code> 
+	 * @param annotations 
 	 * @return a <code>Description</code> named <code>name</code>
 	 */
-	public static Description createSuiteDescription(String name) {
-		return new Description(name);
+	public static Description createSuiteDescription(String name, Annotation... annotations) {
+		return new Description(name, annotations);
 	}
 
 	/**
@@ -36,10 +40,11 @@
 	 * Generally, this will be a leaf <code>Description</code>.
 	 * @param clazz the class of the test
 	 * @param name the name of the test (a method name for test annotated with {@link org.junit.Test})
+	 * @param annotations meta-data about the test, for downstream interpreters
 	 * @return a <code>Description</code> named <code>name</code>
 	 */
-	public static Description createTestDescription(Class<?> clazz, String name) {
-		return new Description(String.format("%s(%s)", name, clazz.getName()));
+	public static Description createTestDescription(Class<?> clazz, String name, Annotation... annotations) {
+		return new Description(String.format("%s(%s)", name, clazz.getName()), annotations);
 	}
 
 	/**
@@ -48,7 +53,7 @@
 	 * @return a <code>Description</code> of <code>testClass</code>
 	 */
 	public static Description createSuiteDescription(Class<?> testClass) {
-		return new Description(testClass.getName());
+		return new Description(testClass.getName(), testClass.getAnnotations());
 	}
 	
 	public static final Description EMPTY= new Description("No Tests");
@@ -57,12 +62,11 @@
 	private final ArrayList<Description> fChildren= new ArrayList<Description>();
 	private final String fDisplayName;
 	
-	/**
-	 * @deprecated (since 4.3) use the static factories (createTestDescription, createSuiteDescription) instead
-	 */
-	@Deprecated
-	protected Description(final String displayName) {
+	private final Annotation[] fAnnotations;
+	
+	private Description(final String displayName, Annotation... annotations) {
 		fDisplayName= displayName;
+		fAnnotations= annotations;
 	}
 
 	/**
@@ -131,4 +135,23 @@
 	public String toString() {
 		return getDisplayName();
 	}
+
+	public boolean isEmpty() {
+		return equals(EMPTY);
+	}
+
+	public Description childlessCopy() {
+		return new Description(fDisplayName, fAnnotations);
+	}
+
+	public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
+		for (Annotation each : fAnnotations)
+			if (each.annotationType().equals(annotationType))
+				return annotationType.cast(each);
+		return null;
+	}
+
+	public Collection<Annotation> getAnnotations() {
+		return Arrays.asList(fAnnotations);
+	}
 }
\ No newline at end of file


-------------------------------------------------------------------------
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/