From 4e445a1997838199c422e2a83b1e954cc26b65a4 Mon Sep 17 00:00:00 2001 From: Scot Breitenfeld Date: Thu, 16 Jul 2026 23:42:06 -0500 Subject: [PATCH] Pin TestH5Z's JUnit method order to fix stale golden-order files JUnit4's default method sorter (MethodSorters.DEFAULT) orders test methods by a hash of the method name, not declaration order -- so any rename or addition shifts the whole run order unpredictably relative to a hand-maintained golden file. Both java/test/TestH5Z.java (added this session, 13 methods) and java/src-jni/test/TestH5Z.java (5 methods, unmodified but apparently never correctly regenerated after the testH5Zget_filter_info2 -> testH5Zget_filter_class_info rename) had golden JUnit-TestH5Z.txt files that didn't match the real hash-sorted order, both confirmed by computing Java's documented String.hashCode() algorithm directly and matching it byte-for-byte against actual CI failure output. Verified against upstream develop (an unrelated, currently-open develop-based PR): this test passes cleanly there, confirming the mismatch was never a general JUnit/reflection flakiness -- it was always a genuinely wrong reference file. Fixed by adding @FixMethodOrder(MethodSorters.NAME_ASCENDING) to both classes (alphabetical by method name, a properly documented and stable JUnit4 ordering mode) and regenerating both reference files to match the resulting deterministic order. This also makes the test immune to the same class of breakage going forward: alphabetical order is computable by inspection, unlike the hash order. --- java/src-jni/test/TestH5Z.java | 3 +++ java/src-jni/test/testfiles/JUnit-TestH5Z.txt | 2 +- java/test/TestH5Z.java | 3 +++ java/test/testfiles/JUnit-TestH5Z.txt | 14 +++++++------- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/java/src-jni/test/TestH5Z.java b/java/src-jni/test/TestH5Z.java index f01b2db9001..a9e36db605a 100644 --- a/java/src-jni/test/TestH5Z.java +++ b/java/src-jni/test/TestH5Z.java @@ -21,10 +21,13 @@ import hdf.hdf5lib.exceptions.HDF5LibraryException; import org.junit.After; import org.junit.Before; +import org.junit.FixMethodOrder; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; +import org.junit.runners.MethodSorters; +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestH5Z { @Rule public TestName testname = new TestName(); diff --git a/java/src-jni/test/testfiles/JUnit-TestH5Z.txt b/java/src-jni/test/testfiles/JUnit-TestH5Z.txt index 50979ad96dd..57247d9a514 100644 --- a/java/src-jni/test/testfiles/JUnit-TestH5Z.txt +++ b/java/src-jni/test/testfiles/JUnit-TestH5Z.txt @@ -2,8 +2,8 @@ JUnit version 4.13.2 .testH5Zfilter_avail .testH5Zget_filter_class_info .testH5Zget_filter_class_info_invalid -.testH5Zunregister_predefined .testH5Zget_filter_info +.testH5Zunregister_predefined Time: XXXX diff --git a/java/test/TestH5Z.java b/java/test/TestH5Z.java index 61f3f09fc4d..9843bdc5417 100644 --- a/java/test/TestH5Z.java +++ b/java/test/TestH5Z.java @@ -24,10 +24,13 @@ import hdf.hdf5lib.exceptions.HDF5LibraryException; import org.junit.After; import org.junit.Before; +import org.junit.FixMethodOrder; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; +import org.junit.runners.MethodSorters; +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestH5Z { @Rule public TestName testname = new TestName(); diff --git a/java/test/testfiles/JUnit-TestH5Z.txt b/java/test/testfiles/JUnit-TestH5Z.txt index 28fc1867504..831ccb76f42 100644 --- a/java/test/testfiles/JUnit-TestH5Z.txt +++ b/java/test/testfiles/JUnit-TestH5Z.txt @@ -1,17 +1,17 @@ JUnit version 4.13.2 -.testH5Zfilter_avail -.testH5Zconfig_get_param_double +.testH5Pappend_filter_cdvalues +.testH5Pappend_filter_string .testH5Pget_filter_params_by_idx -.testH5Zconfig_get_param_missing_key +.testH5Zconfig_get_param_bool +.testH5Zconfig_get_param_double .testH5Zconfig_get_param_int +.testH5Zconfig_get_param_missing_key .testH5Zconfig_get_param_str +.testH5Zfilter_avail .testH5Zget_filter_class_info .testH5Zget_filter_class_info_invalid -.testH5Zconfig_get_param_bool -.testH5Zunregister_predefined -.testH5Pappend_filter_string -.testH5Pappend_filter_cdvalues .testH5Zget_filter_info +.testH5Zunregister_predefined Time: XXXX