Changeset 19055 in josm


Ignore:
Timestamp:
2024-04-23T18:41:05+02:00 (2 weeks ago)
Author:
taylor.smock
Message:

Fix tests in Java 21

  • Regenerate Java 21 image files (probably from r19043: Drop COMPAT locale provider).
  • Remove Java 8 image files, since we no longer support Java 8.
  • Fix an issue where Java 21 uses a non-breaking space between time and AM/PM.
Location:
trunk/test
Files:
23 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/functional/org/openstreetmap/josm/gui/mappaint/MapCSSRendererTest.java

    r18870 r19055  
    2121import java.util.Collections;
    2222import java.util.List;
    23 import java.util.Locale;
    2423import java.util.function.Consumer;
    2524import java.util.stream.Collectors;
     
    4241import org.openstreetmap.josm.testutils.annotations.Projection;
    4342import org.openstreetmap.josm.tools.ColorHelper;
    44 import org.openstreetmap.josm.tools.Utils;
    4543
    4644/**
     
    7068    public static Collection<Object[]> runs() {
    7169        return Stream.of(
    72                 /** Tests for StyledMapRenderer#drawNodeSymbol */
     70                /* Tests for StyledMapRenderer#drawNodeSymbol */
    7371                new TestConfig("node-shapes", AREA_DEFAULT)
    7472                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    7573
    76                 /** Text for nodes */
     74                /* Text for nodes */
    7775                new TestConfig("node-text", AREA_DEFAULT).usesFont("DejaVu Sans")
    7876                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    7977
    80                 /** Tests that StyledMapRenderer#drawWay respects width */
     78                /* Tests that StyledMapRenderer#drawWay respects width */
    8179                new TestConfig("way-width", AREA_DEFAULT)
    8280                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    8381
    84                 /** Tests the way color property, including alpha */
     82                /* Tests the way color property, including alpha */
    8583                new TestConfig("way-color", AREA_DEFAULT)
    8684                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    8785
    88                 /** Tests dashed ways. */
     86                /* Tests dashed ways. */
    8987                new TestConfig("way-dashes", AREA_DEFAULT)
    9088                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    9189
    92                 /** Tests dashed way clamping algorithm */
     90                /* Tests dashed way clamping algorithm */
    9391                new TestConfig("way-dashes-clamp", AREA_DEFAULT)
    9492                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    9593
    96                 /** Tests fill-color property */
     94                /* Tests fill-color property */
    9795                new TestConfig("area-fill-color", AREA_DEFAULT),
    9896
    99                 /** Tests the fill-image property. */
     97                /* Tests the fill-image property. */
    10098                new TestConfig("area-fill-image", AREA_DEFAULT)
    10199                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    102100
    103                 /** Tests area label drawing/placement */
     101                /* Tests area label drawing/placement */
    104102                new TestConfig("area-text", AREA_DEFAULT)
    105103                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    106104
    107                 /** Tests area icon drawing/placement */
     105                /* Tests area icon drawing/placement */
    108106                new TestConfig("area-icon", AREA_DEFAULT)
    109107                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    110108
    111                 /** Tests if all styles are sorted correctly. Tests {@link StyleRecord#compareTo(StyleRecord)} */
     109                /* Tests if all styles are sorted correctly. Tests {@link StyleRecord#compareTo(StyleRecord)} */
    112110                new TestConfig("order", AREA_DEFAULT)
    113111                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    114112
    115                 /** Tests repeat-image feature for ways */
     113                /* Tests repeat-image feature for ways */
    116114                new TestConfig("way-repeat-image", AREA_DEFAULT)
    117115                        .setThresholdPixels(2100).setThresholdTotalColorDiff(93_000),
    118                 /** Tests the clamping for repeat-images and repeat-image-phase */
     116                /* Tests the clamping for repeat-images and repeat-image-phase */
    119117                new TestConfig("way-repeat-image-clamp", AREA_DEFAULT)
    120118                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    121119
    122                 /** Tests text along a way */
     120                /* Tests text along a way */
    123121                new TestConfig("way-text", AREA_DEFAULT)
    124122                        .setThresholdPixels(3400).setThresholdTotalColorDiff(0),
    125123
    126                 /** Another test for node shapes */
     124                /* Another test for node shapes */
    127125                new TestConfig("node-shapes2").setImageWidth(600)
    128126                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    129                 /** Tests default values for node shapes */
     127                /* Tests default values for node shapes */
    130128                new TestConfig("node-shapes-default")
    131129                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    132                 /** Tests node shapes with both fill and stroke combined */
     130                /* Tests node shapes with both fill and stroke combined */
    133131                new TestConfig("node-shapes-combined")
    134132                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    135                 /** Another test for dashed ways */
     133                /* Another test for dashed ways */
    136134                new TestConfig("way-dashes2")
    137135                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    138                 /** Tests node text placement */
     136                /* Tests node text placement */
    139137                new TestConfig("node-text2")
    140138                        .setThresholdPixels(1020).setThresholdTotalColorDiff(0),
    141                 /** Tests relation link selector */
     139                /* Tests relation link selector */
    142140                new TestConfig("relation-linkselector")
    143141                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    144                 /** Tests parent selector on relation */
     142                /* Tests parent selector on relation */
    145143                new TestConfig("relation-parentselector")
    146144                        .setThresholdPixels(0).setThresholdTotalColorDiff(0),
    147145
    148                 /** Tests evaluation of expressions */
     146                /* Tests evaluation of expressions */
    149147                new TestConfig("eval").setImageWidth(600)
    150148                        .setThresholdPixels(6610).setThresholdTotalColorDiff(0)
     
    163161    @MethodSource("runs")
    164162    void testRender(TestConfig testConfig, String ignored) throws Exception {
    165         // This test only runs on OpenJDK.
    166         // It is ignored for other Java versions since they differ slightly in their rendering engine.
    167         String javaHome = System.getProperty("java.home");
    168         assumeTrue(javaHome != null && javaHome.toLowerCase(Locale.ENGLISH).contains("openjdk"), "Test requires openJDK");
    169 
    170163        List<String> fonts = Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
    171164        for (String font : testConfig.fonts) {
     
    228221        }
    229222        final BufferedImage reference = ImageIO.read(referenceImageFile);
    230         assertEquals(image.getWidth(), reference.getWidth());
    231         assertEquals(image.getHeight(), reference.getHeight());
     223        assertEquals(reference.getWidth(), image.getWidth());
     224        assertEquals(reference.getHeight(), image.getHeight());
    232225
    233226        StringBuilder differences = new StringBuilder();
     
    331324        /**
    332325         * Set the number of pixels that can differ.
    333          *
     326         * <p>
    334327         * Needed due to somewhat platform dependent font rendering.
    335328         * @param thresholdPixels the number of pixels that can differ
     
    359352
    360353        public File getReference() {
    361             // Java 8 renders SVG images differently, thus, use separate reference files
    362             final String javaSuffix = Utils.getJavaVersion() == 8 ? "-java8" : "";
    363             return new File(getTestDirectory() + "/reference" + javaSuffix + ".png");
     354            // Sometimes Java changes how things are rendered. When that happens, use separate reference files. It is
     355            // usually "reference" + javaSuffix + ".png".
     356            return new File(getTestDirectory() + "/reference.png");
    364357        }
    365358
  • trunk/test/functional/org/openstreetmap/josm/tools/ImageProviderTest.java

    r18856 r19055  
    189189
    190190    private static File getReferenceFile(String reference) {
    191         // Java 8 and Java 21 render SVG images differently, thus, use separate reference files
    192         final String javaSuffix;
    193         switch (Utils.getJavaVersion()) {
    194             case 8: javaSuffix = "-java8";
    195             break;
    196             case 21: javaSuffix = "-java21";
    197             break;
    198             default: javaSuffix = "";
    199         }
     191        // Java 11-17 and Java 21 render SVG images differently, thus, use separate reference files
     192        final String javaSuffix = Utils.getJavaVersion() == 21 ? "-java21" : "";
    200193        return new File(TestUtils.getTestDataRoot() + "/" + ImageProviderTest.class.getSimpleName() + javaSuffix + "/" + reference + ".png");
    201194    }
  • trunk/test/unit/org/openstreetmap/josm/tools/date/DateUtilsTest.java

    r19054 r19055  
    2424import org.openstreetmap.josm.testutils.annotations.I18n;
    2525import org.openstreetmap.josm.tools.UncheckedParseException;
     26import org.openstreetmap.josm.tools.Utils;
    2627
    2728import net.trajano.commons.testing.UtilityClassTestUtil;
     
    153154    @Test
    154155    void testFormatTime() {
    155         assertEquals("12:00 AM", DateUtils.formatTime(new Date(0), DateFormat.SHORT));
    156         assertEquals("1:00 AM", DateUtils.formatTime(new Date(60 * 60 * 1000), DateFormat.SHORT));
    157         assertEquals("12:00 AM", DateUtils.formatTime(new Date(999), DateFormat.SHORT));
     156        // Somewhere between Java 17 and Java 21, a non-breaking space replaced the original space between the time and AM/PM.
     157        final var separator = Utils.getJavaVersion() >= 21 ? '\u202f' : ' ';
     158        final var twelveAM = "12:00" + separator + "AM";
     159        assertEquals(twelveAM, DateUtils.formatTime(new Date(0), DateFormat.SHORT));
     160        assertEquals("1:00" + separator + "AM", DateUtils.formatTime(new Date(60 * 60 * 1000), DateFormat.SHORT));
     161        assertEquals(twelveAM, DateUtils.formatTime(new Date(999), DateFormat.SHORT));
    158162        // ignore seconds
    159         assertEquals("12:00 AM", DateUtils.formatTime(new Date(5999), DateFormat.SHORT));
     163        assertEquals(twelveAM, DateUtils.formatTime(new Date(5999), DateFormat.SHORT));
    160164
    161165        setTimeZone(TimeZone.getTimeZone("Europe/Berlin"));
    162         assertEquals("1:00:00 AM GMT+01:00", DateUtils.formatTime(new Date(0), DateFormat.LONG), "This is mostly dependent upon java.locale.providers. CET is also OK.");
     166        assertEquals("1:00:00" + separator + "AM GMT+01:00", DateUtils.formatTime(new Date(0), DateFormat.LONG), "This is mostly dependent upon java.locale.providers. CET is also OK.");
    163167    }
    164168
Note: See TracChangeset for help on using the changeset viewer.