Changeset 19613 in josm for trunk/test/functional
- Timestamp:
- 2026-08-11T15:36:21+02:00 (34 hours ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/functional/org/openstreetmap/josm/tools/ImageProviderTest.java
r19588 r19613 21 21 import java.util.logging.Handler; 22 22 import java.util.logging.LogRecord; 23 import java.util.regex.Matcher; 24 import java.util.regex.Pattern; 23 25 24 26 import javax.swing.ImageIcon; … … 187 189 } 188 190 191 private static final Pattern JAVA_SUFFIX_PATTERN = Pattern.compile("-java(\\d+)\\.png$"); 192 193 /** 194 * Determine the reference image file to use for the given reference name. 195 * <p> 196 * Different Java versions may render SVG images slightly differently. 197 * When this happens, an additional reference file with a {@code -javaXX} suffix 198 * can be added next to the original reference file. This method 199 * then picks the reference file whose suffixed Java version is the closest (but not newer) to the 200 * Java version currently running the test, falling back to the unsuffixed file otherwise. 201 * <p> 202 * This way, new reference files only need to be added when a new Java version actually renders 203 * something differently, without needing to touch this method. 204 * @param reference the reference identifier 205 * @return the most appropriate reference file for the current Java version 206 */ 189 207 private static File getReferenceFile(String reference) { 190 // Java 11-17 and Java 21 render SVG images differently, thus, use separate reference files 191 final String javaSuffix = Utils.getJavaVersion() == 21 ? "-java21" : ""; 192 return new File(TestUtils.getTestDataRoot() + "/" + ImageProviderTest.class.getSimpleName() + javaSuffix + "/" + reference + ".png"); 208 final File directory = new File(TestUtils.getTestDataRoot() + "/" + ImageProviderTest.class.getSimpleName()); 209 final int javaVersion = Utils.getJavaVersion(); 210 final File[] candidates = directory.listFiles((dir, name) -> name.startsWith(reference + "-java")); 211 File bestFile = null; 212 int bestVersion = -1; 213 if (candidates != null) { 214 for (File candidate : candidates) { 215 Matcher matcher = JAVA_SUFFIX_PATTERN.matcher(candidate.getName()); 216 if (matcher.find()) { 217 int version = Integer.parseInt(matcher.group(1)); 218 if (version <= javaVersion && version > bestVersion) { 219 bestVersion = version; 220 bestFile = candidate; 221 } 222 } 223 } 224 } 225 return bestFile != null ? bestFile : new File(directory, reference + ".png"); 193 226 } 194 227
Note:
See TracChangeset
for help on using the changeset viewer.
