HHH-6014: Adding a priority annotation. Higher test method priority means that the method will be executed first.

This commit is contained in:
adamw 2011-04-01 23:10:58 +02:00
parent 8e1110634f
commit 9165b0c235
2 changed files with 39 additions and 2 deletions

View File

@ -12,6 +12,7 @@ import org.junit.runners.model.TestClass;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
@ -65,9 +66,28 @@ public class EnversRunner extends Suite {
@Override
protected String testName(final FrameworkMethod method) {
return String.format("%s[%s]", method.getName(),
fParameterSetNumber);
fParameterSetNumber);
}
}
@Override
protected List<FrameworkMethod> doComputation() {
List<FrameworkMethod> frameworkMethods = super.doComputation();
Collections.sort(frameworkMethods, new Comparator<FrameworkMethod>() {
private int getPriority(FrameworkMethod fm) {
Priority p = fm.getAnnotation(Priority.class);
return p == null ? 0 : p.value();
}
@Override
public int compare(FrameworkMethod fm1, FrameworkMethod fm2) {
return getPriority(fm2) - getPriority(fm1);
}
});
return frameworkMethods;
}
}
private final ArrayList<Runner> runners= new ArrayList<Runner>();

View File

@ -0,0 +1,17 @@
package org.hibernate.envers.test;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation for specifyfing test method priority. Methods with higher priorities execute earlier.
* If the annotation is not present priority 0 is assumed.
* @author Adam Warski (adam at warski dot org)
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface Priority {
int value();
}