Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:13.1:Update
junit4
jdk7-testfailure.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File jdk7-testfailure.patch of Package junit4
diff --git src/main/java/junit/framework/TestSuite.java src/main/java/junit/framework/TestSuite.java index 336efd1..b67006a 100644 --- src/main/java/junit/framework/TestSuite.java +++ src/main/java/junit/framework/TestSuite.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.Vector; +import org.junit.internal.MethodSorter; /** * <p>A <code>TestSuite</code> is a <code>Composite</code> of Tests. @@ -146,7 +147,7 @@ public class TestSuite implements Test { Class<?> superClass= theClass; List<String> names= new ArrayList<String>(); while (Test.class.isAssignableFrom(superClass)) { - for (Method each : superClass.getDeclaredMethods()) + for (Method each : MethodSorter.getDeclaredMethods(superClass)) addTestMethod(each, names, theClass); superClass= superClass.getSuperclass(); } diff --git src/main/java/org/junit/internal/MethodSorter.java src/main/java/org/junit/internal/MethodSorter.java new file mode 100644 index 0000000..844e1c6 --- /dev/null +++ src/main/java/org/junit/internal/MethodSorter.java @@ -0,0 +1,35 @@ +package org.junit.internal; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Comparator; + +public class MethodSorter { + + /** + * Gets declared methods of a class in a predictable order. + * Using the "natural" order is unwise since the Java platform does not + * specify any particular order, and in fact JDK 7 returns a more or less + * random order; well-written test code would not assume any order, but some + * does, and a predictable failure is better than a random failure on + * certain platforms. + * @param clazz a class + * @return same as {@link Class#getDeclaredMethods} but sorted + * @see <a href="http://bugs.sun.com/view_bug.do?bug_id=7023180">JDK + * (non-)bug #7023180</a> + */ + public static Method[] getDeclaredMethods(Class<?> clazz) { + Method[] methods = clazz.getDeclaredMethods(); + Arrays.sort(methods, new Comparator<Method>() { + @Override public int compare(Method m1, Method m2) { + // Alpha sort by name, and secondarily by other differentiating + // information (parameters and return type). + return m1.toString().compareTo(m2.toString()); + } + }); + return methods; + } + + private MethodSorter() {} + +} diff --git src/main/java/org/junit/internal/runners/TestClass.java src/main/java/org/junit/internal/runners/TestClass.java index 1ca2b9d..69f404f 100644 --- src/main/java/org/junit/internal/runners/TestClass.java +++ src/main/java/org/junit/internal/runners/TestClass.java @@ -11,6 +11,7 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.internal.MethodSorter; import org.junit.runners.BlockJUnit4ClassRunner; /** @@ -41,7 +42,7 @@ public class TestClass { public List<Method> getAnnotatedMethods(Class<? extends Annotation> annotationClass) { List<Method> results= new ArrayList<Method>(); for (Class<?> eachClass : getSuperClasses(fClass)) { - Method[] methods= eachClass.getDeclaredMethods(); + Method[] methods= MethodSorter.getDeclaredMethods(eachClass); for (Method eachMethod : methods) { Annotation annotation= eachMethod.getAnnotation(annotationClass); if (annotation != null && ! isShadowed(eachMethod, results)) diff --git src/main/java/org/junit/runners/model/TestClass.java src/main/java/org/junit/runners/model/TestClass.java index 891059a..708f9c5 100644 --- src/main/java/org/junit/runners/model/TestClass.java +++ src/main/java/org/junit/runners/model/TestClass.java @@ -12,6 +12,7 @@ import java.util.Map; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.internal.MethodSorter; /** * Wraps a class to be run, providing method validation and annotation searching @@ -36,7 +37,7 @@ public class TestClass { "Test class can only have one constructor"); for (Class<?> eachClass : getSuperClasses(fClass)) { - for (Method eachMethod : eachClass.getDeclaredMethods()) + for (Method eachMethod : MethodSorter.getDeclaredMethods(eachClass)) addToAnnotationLists(new FrameworkMethod(eachMethod), fMethodsForAnnotations); for (Field eachField : eachClass.getDeclaredFields())
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor