Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/test/java/org/junit/internal/MethodSorterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

import org.junit.FixMethodOrder;
Expand Down Expand Up @@ -147,6 +148,21 @@ void epsilon() {
public void testJvmMethodSorter() {
Method[] fromJvmWithSynthetics = DummySortJvm.class.getDeclaredMethods();
Method[] sorted = MethodSorter.getDeclaredMethods(DummySortJvm.class);

Comparator<Method> methodComparator = new Comparator<Method>() {
@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);
Copy link
Member

@kcooney kcooney Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test now simply verifies that the two methods return the same values, ignoring order, so with these changes it's not a particularly good test.

The ordering of methods returned by getDeclaredMethods() is no longer guaranteed as of JDK 7. I think the only way to make this test useful but not flaky would be to skip the test if the JDK is 7 or greater.


assertArrayEquals(fromJvmWithSynthetics, sorted);
}

Expand Down