Permalink
Browse files

Merge pull request #440 from ibeauregard/testNameAsc

Make MethodSorters deterministic in JDK 7
  • Loading branch information...
2 parents 6f74b19 + 8424e26 commit c228881359e2a4ccd0d5972c646f043ec42d62e0 @kcooney kcooney committed Jun 1, 2012
@@ -17,22 +17,21 @@ public int compare(Method m1, Method m2) {
if (i1 != i2) {
return i1 < i2 ? -1 : 1;
}
- return MethodSorter.compare(m1.toString(), m2.toString());
+ return NAME_ASCENDING.compare(m1, m2);
}
};
/**
- * Method name ascending lexicograhic sort order
+ * Method name ascending lexicographic sort order, with {@link Method#toString()} as a tiebreaker
*/
public static Comparator<Method> NAME_ASCENDING= new Comparator<Method>() {
public int compare(Method m1, Method m2) {
- return MethodSorter.compare(m1.getName(), m2.getName());
+ final int comparison = m1.getName().compareTo(m2.getName());
+ if (comparison != 0)
+ return comparison;
+ return m1.toString().compareTo(m2.toString());
}
};
-
- private static int compare(String s1, String s2) {
- return s1.compareTo(s2);
- }
/**
* Gets declared methods of a class in a predictable order, unless @FixMethodOrder(MethodSorters.JVM) is specified.
@@ -10,11 +10,17 @@
* Defines common {@link MethodSorter} implementations.
*/
public enum MethodSorters {
- /** Sorts the test methods by the method name, in lexicographic order */
+ /** Sorts the test methods by the method name, in lexicographic order,
+ * with {@link Method#toString()} used as a tiebreaker
+ */
NAME_ASCENDING(MethodSorter.NAME_ASCENDING),
- /** Sorts the test methods by the method name, in reverse lexicographic order */
+
+ /** Leaves the test methods in the order returned by the JVM.
+ * Note that the order from the JVM may vary from run to run
+ */
JVM(null),
- /** the default value, deterministic, but not predictable */
+
+ /** Sorts the test methods in a deterministic, but not predictable, order */
DEFAULT(MethodSorter.DEFAULT);
private final Comparator<Method> fComparator;
@@ -6,6 +6,7 @@
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
+
import static org.junit.Assert.*;
public class MethodSorterTest {

0 comments on commit c228881

Please sign in to comment.