From 9165b0c235dfb5d01187c9b14e7a00b128db2c0f Mon Sep 17 00:00:00 2001 From: adamw Date: Fri, 1 Apr 2011 23:10:58 +0200 Subject: [PATCH] HHH-6014: Adding a priority annotation. Higher test method priority means that the method will be executed first. --- .../hibernate/envers/test/EnversRunner.java | 24 +++++++++++++++++-- .../org/hibernate/envers/test/Priority.java | 17 +++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 hibernate-envers/src/test/java/org/hibernate/envers/test/Priority.java diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/EnversRunner.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/EnversRunner.java index f24fcf74a8..cf5cc8022f 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/EnversRunner.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/EnversRunner.java @@ -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 doComputation() { + List frameworkMethods = super.doComputation(); + + Collections.sort(frameworkMethods, new Comparator() { + 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 runners= new ArrayList(); diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/Priority.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/Priority.java new file mode 100644 index 0000000000..f18f9d9b8d --- /dev/null +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/Priority.java @@ -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(); +}