Make test 100 not depend on undefined ordering.
Test 100 tested the officially unspecified ordering of the return
values of various reflection methods. This makes the test only check
the values contained in the array but not the order.
Change-Id: I775646321831f28f722d1db97335231df03ff923
diff --git a/test/100-reflect2/src/Main.java b/test/100-reflect2/src/Main.java
index bf3a574..1245852 100644
--- a/test/100-reflect2/src/Main.java
+++ b/test/100-reflect2/src/Main.java
@@ -157,10 +157,28 @@
System.out.println(o + " (" + (o != null ? o.getClass() : "null") + ")");
}
+ /**
+ * Sorts the input array using the comparator and returns the sorted array.
+ */
+ private static Object[] sort(Object[] objects, Comparator<Object> comp) {
+ Arrays.sort(objects, comp);
+ return objects;
+ }
+
public static void testMethodReflection() throws Exception {
- System.out.println(Arrays.toString(String.class.getDeclaredConstructors()));
- System.out.println(Arrays.toString(String.class.getDeclaredFields()));
- System.out.println(Arrays.toString(String.class.getDeclaredMethods()));
+ Comparator<Object> comp = new Comparator<Object>() {
+ public int compare(Object a, Object b) {
+ return a.toString().compareTo(b.toString());
+ }
+ public boolean equals(Object b) {
+ return this == b;
+ }
+ };
+
+ // Sort the return values by their string values since the order is undefined by the spec.
+ System.out.println(Arrays.toString(sort(String.class.getDeclaredConstructors(), comp)));
+ System.out.println(Arrays.toString(sort(String.class.getDeclaredFields(), comp)));
+ System.out.println(Arrays.toString(sort(String.class.getDeclaredMethods(), comp)));
System.out.println(Arrays.toString(Main.class.getInterfaces()));
System.out.println(Arrays.toString(String.class.getInterfaces()));