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 JVM
	 * 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.
	 * Uses an unspecified but deterministic order.
	 * 
	 * @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>() {
			public int compare(Method m1, Method m2) {
				int i1= m1.getName().hashCode();
				int i2= m2.getName().hashCode();
				return i1 != i2 ? i1 - i2 : m1.toString().compareTo(
						m2.toString());
			}
		});
		return methods;
	}

	private MethodSorter() {
	}

}

@@ -143,14 +143,20 @@
  %7B%0A%0A
-%09/**%0A%09
+    /**%0A    
  * G
@@ -210,16 +210,23 @@
 e order.
+%0A     *
  Using t
@@ -231,20 +231,16 @@
  the JVM
-%0A%09 *
  order i
@@ -280,16 +280,23 @@
 does not
+%0A     *
  specify
@@ -310,20 +310,16 @@
 rticular
-%0A%09 *
  order, 
@@ -358,16 +358,23 @@
  or less
+%0A     *
  random 
@@ -379,20 +379,16 @@
 m order;
-%0A%09 *
  well-wr
@@ -439,16 +439,23 @@
 but some
+%0A     *
  does, a
@@ -458,20 +458,16 @@
 s, and a
-%0A%09 *
  predict
@@ -513,16 +513,23 @@
 ilure on
+%0A     *
  certain
@@ -539,20 +539,16 @@
 atforms.
-%0A%09 *
  Uses an
@@ -589,14 +589,12 @@
 er.%0A
-%09 * %0A%09
+    
  * @
@@ -608,23 +608,8 @@
 lazz
-%0A%09 *           
  a c
@@ -613,17 +613,20 @@
 a class%0A
-%09
+    
  * @retu
@@ -680,17 +680,20 @@
  sorted%0A
-%09
+    
  * @see 
@@ -753,19 +753,23 @@
 80%22%3EJDK%0A
-%09
+    
  *
+ 
       (n
@@ -793,14 +793,20 @@
 /a%3E%0A
-%09 */%0A%09
+     */%0A    
 publ
@@ -861,18 +861,24 @@
 lazz) %7B%0A
-%09%09
+        
 Method%5B%5D
@@ -885,16 +885,17 @@
  methods
+ 
 = clazz.
@@ -916,18 +916,24 @@
 hods();%0A
-%09%09
+        
 Arrays.s
@@ -972,19 +972,38 @@
 od%3E() %7B%0A
-%09%09%09
+            @Override 
 public i
@@ -1041,18 +1041,31 @@
 ) %7B%0A
-%09%09%09%09
+                
 int i1
+ 
 = m1
@@ -1091,18 +1091,31 @@
 ();%0A
-%09%09%09%09
+                
 int i2
+ 
 = m2
@@ -1137,20 +1137,32 @@
 Code();%0A
-%09%09%09%09
+                
 return i
@@ -1209,15 +1209,8 @@
 eTo(
-%0A%09%09%09%09%09%09
 m2.t
@@ -1225,21 +1225,42 @@
 ));%0A
-%09%09%09%7D%0A%09%09%7D);%0A%09%09
+            %7D%0A        %7D);%0A        
 retu
@@ -1275,13 +1275,19 @@
 ds;%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 priv
@@ -1310,10 +1310,8 @@
 () %7B
-%0A%09
 %7D%0A%0A%7D

Revert "Removed offending @Override annotation (#382)"