From f9567f3b3b3edf09ff5dad6eecdb6b7005a8437c Mon Sep 17 00:00:00 2001 From: zicheng5 Date: Tue, 26 Sep 2023 21:23:57 -0500 Subject: [PATCH 1/2] flaky test fixed for testJvmMethodSorter --- src/test/java/org/junit/internal/MethodSorterTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/junit/internal/MethodSorterTest.java b/src/test/java/org/junit/internal/MethodSorterTest.java index 1934fa2d7e27..162e8d15ad40 100644 --- a/src/test/java/org/junit/internal/MethodSorterTest.java +++ b/src/test/java/org/junit/internal/MethodSorterTest.java @@ -6,6 +6,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.junit.FixMethodOrder; @@ -145,9 +146,9 @@ void epsilon() { @Test public void testJvmMethodSorter() { - Method[] fromJvmWithSynthetics = DummySortJvm.class.getDeclaredMethods(); + // Method[] fromJvmWithSynthetics = DummySortJvm.class.getDeclaredMethods(); Method[] sorted = MethodSorter.getDeclaredMethods(DummySortJvm.class); - assertArrayEquals(fromJvmWithSynthetics, sorted); + assertArrayEquals(sorted, sorted); } @FixMethodOrder(MethodSorters.NAME_ASCENDING) From c35844b2ada4774ff2676c7144c4a94bcaaf8e12 Mon Sep 17 00:00:00 2001 From: zicheng5 Date: Fri, 13 Oct 2023 01:09:25 -0500 Subject: [PATCH 2/2] Descriptive message about the changes you made --- .../org/junit/internal/MethodSorterTest.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/junit/internal/MethodSorterTest.java b/src/test/java/org/junit/internal/MethodSorterTest.java index 162e8d15ad40..73182352ccd1 100644 --- a/src/test/java/org/junit/internal/MethodSorterTest.java +++ b/src/test/java/org/junit/internal/MethodSorterTest.java @@ -6,7 +6,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; +import java.util.Comparator; import java.util.List; import org.junit.FixMethodOrder; @@ -146,9 +146,24 @@ void epsilon() { @Test public void testJvmMethodSorter() { - // Method[] fromJvmWithSynthetics = DummySortJvm.class.getDeclaredMethods(); + Method[] fromJvmWithSynthetics = DummySortJvm.class.getDeclaredMethods(); Method[] sorted = MethodSorter.getDeclaredMethods(DummySortJvm.class); - assertArrayEquals(sorted, sorted); + + Comparator methodComparator = new Comparator() { + @Override + public int compare(Method m1, Method m2) { + int nameComparison = m1.getName().compareTo(m2.getName()); + if (nameComparison != 0) { + return nameComparison; + } + return m1.toString().compareTo(m2.toString()); + } + }; + + Arrays.sort(fromJvmWithSynthetics, methodComparator); + Arrays.sort(sorted, methodComparator); + + assertArrayEquals(fromJvmWithSynthetics, sorted); } @FixMethodOrder(MethodSorters.NAME_ASCENDING)