Changeset 19056 in josm


Ignore:
Timestamp:
2024-04-24T20:02:57+02:00 (7 weeks ago)
Author:
taylor.smock
Message:

Fix last failing test in Java 21

  • Generate Java 21 image files (probably from r19043: Drop COMPAT locale provider).
  • Replace most deprecated function calls and classes in tests with non-deprecated functions.
Location:
trunk/test
Files:
10 edited
1 copied

Legend:

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

    r19055 r19056  
    4141import org.openstreetmap.josm.testutils.annotations.Projection;
    4242import org.openstreetmap.josm.tools.ColorHelper;
     43import org.openstreetmap.josm.tools.Utils;
    4344
    4445/**
     
    354355            // Sometimes Java changes how things are rendered. When that happens, use separate reference files. It is
    355356            // usually "reference" + javaSuffix + ".png".
     357            final File customReferenceFile = new File(getTestDirectory() + "/reference-java" + Utils.getJavaVersion() + ".png");
     358            if (customReferenceFile.isFile()) {
     359                return customReferenceFile;
     360            }
    356361            return new File(getTestDirectory() + "/reference.png");
    357362        }
  • trunk/test/unit/org/openstreetmap/josm/TestUtils.java

    r18991 r19056  
    592592            ) {
    593593                assertArrayEquals(
    594                     Utils.readBytesFromStream(streamA),
    595                     Utils.readBytesFromStream(streamB)
     594                    streamA.readAllBytes(),
     595                    streamB.readAllBytes()
    596596                );
    597597            }
  • trunk/test/unit/org/openstreetmap/josm/actions/SessionSaveActionTest.java

    r18800 r19056  
    5555
    5656        JOptionPaneSimpleMocker mocker = new JOptionPaneSimpleMocker(Collections.singletonMap(overrideStr, 0));
    57         SessionSaveAction.setCurrentSession(jos, false, Arrays.asList(gpx, osm)); //gpx and OSM layer
     57        SessionSaveAction.setCurrentSession(jos, Arrays.asList(gpx, osm)); //gpx and OSM layer
    5858        MainApplication.getLayerManager().addLayer(gpx); //only gpx layer
    5959        saveAction.actionPerformed(null); //Complain that OSM layer was removed
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/PluginDownloadTaskTest.java

    r18893 r19056  
    1919import org.openstreetmap.josm.plugins.PluginInformation;
    2020import org.openstreetmap.josm.testutils.annotations.AssumeRevision;
    21 import org.openstreetmap.josm.tools.Utils;
    2221
    2322/**
     
    129128            assertArrayEquals(
    130129                existingPluginContents,
    131                 Utils.readBytesFromStream(pluginDirPluginStream)
     130                pluginDirPluginStream.readAllBytes()
    132131            );
    133132        }
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreferenceTestIT.java

    r18893 r19056  
    170170                }
    171171                try {
    172                     byte[] data = Utils.readBytesFromStream(response.getContent());
     172                    byte[] data = response.getContent().readAllBytes();
    173173                    if (response.getResponseCode() < 300) {
    174174                        workingURLs.put(url, data);
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java

    r18893 r19056  
    1717import org.openstreetmap.josm.testutils.annotations.AssertionsInEDT;
    1818import org.openstreetmap.josm.testutils.annotations.HTTPS;
    19 import org.openstreetmap.josm.tools.Utils;
    2019
    2120/**
     
    6059        assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, connection.getResponseCode());
    6160        try (InputStream is = connection.getErrorStream()) {
    62             String responseBody = new String(Utils.readBytesFromStream(is), StandardCharsets.UTF_8);
     61            String responseBody = new String(is.readAllBytes(), StandardCharsets.UTF_8);
    6362            assert responseBody.contains(RequestProcessor.getUsageAsHtml());
    6463        }
  • trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java

    r18870 r19056  
    33
    44import static org.junit.jupiter.api.Assertions.assertEquals;
    5 import static org.junit.jupiter.api.Assertions.fail;
    65
    76import java.awt.Color;
    87import java.io.File;
    98import java.io.IOException;
     9import java.io.UncheckedIOException;
    1010import java.nio.charset.StandardCharsets;
    1111import java.nio.file.Files;
     
    134134                return Collections.list(zipFile.entries()).stream().collect(Collectors.toMap(ZipEntry::getName, e -> {
    135135                    try {
    136                         return Utils.readBytesFromStream(zipFile.getInputStream(e));
     136                        return zipFile.getInputStream(e).readAllBytes();
    137137                    } catch (IOException ex) {
    138                         fail(ex);
     138                        throw new UncheckedIOException(ex);
    139139                    }
    140                     return null;
    141140                }));
    142141            }
     
    275274
    276275        Path path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/gpx_markers_combined.jos");
    277         String expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");
     276        String expected = Files.readString(path).replace("\r", "");
    278277        String actual = new String(bytes.get("session.jos"), StandardCharsets.UTF_8).replace("\r", "");
    279278        assertEquals(expected, actual);
    280279
    281280        path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/data_export.gpx");
    282         expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");
     281        expected = Files.readString(path).replace("\r", "");
    283282        actual = new String(bytes.get("layers/01/data.gpx"), StandardCharsets.UTF_8).replace("\r", "");
    284283        assertEquals(expected, actual);
     
    291290
    292291        path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/gpx_markers.jos");
    293         expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");
     292        expected = Files.readString(path).replace("\r", "");
    294293        actual = new String(bytes.get("session.jos"), StandardCharsets.UTF_8).replace("\r", "");
    295294        assertEquals(expected, actual);
    296295
    297296        path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/data_export.gpx");
    298         expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");
     297        expected = Files.readString(path).replace("\r", "");
    299298        actual = new String(bytes.get("layers/01/data.gpx"), StandardCharsets.UTF_8).replace("\r", "");
    300299        assertEquals(expected, actual);
    301300
    302301        path = Paths.get(TestUtils.getTestDataRoot() + "/sessions/markers.gpx");
    303         expected = new String(Files.readAllBytes(path), StandardCharsets.UTF_8).replace("\r", "");
     302        expected = Files.readString(path).replace("\r", "");
    304303        actual = new String(bytes.get("layers/02/data.gpx"), StandardCharsets.UTF_8).replace("\r", "");
    305304        assertEquals(expected, actual);
  • trunk/test/unit/org/openstreetmap/josm/testutils/annotations/AnnotationUtils.java

    r18106 r19056  
    4848    public static void resetStaticClass(Class<?> clazz) throws ReflectiveOperationException {
    4949        for (Field field : clazz.getDeclaredFields()) {
    50             if (!field.isAccessible()) {
    51                 field.setAccessible(true);
    52             }
    5350            // Don't reset fields that are not static
    5451            if ((field.getModifiers() & Modifier.STATIC) == 0) {
    5552                continue;
     53            }
     54            if (!field.canAccess(null)) {
     55                field.setAccessible(true);
    5656            }
    5757            final boolean isFinal = (field.getModifiers() & Modifier.FINAL) != 0;
  • trunk/test/unit/org/openstreetmap/josm/testutils/annotations/BasicWiremock.java

    r18893 r19056  
    4141
    4242import com.github.tomakehurst.wiremock.WireMockServer;
    43 import com.github.tomakehurst.wiremock.extension.ResponseTransformer;
     43import com.github.tomakehurst.wiremock.client.WireMock;
     44import com.github.tomakehurst.wiremock.extension.ResponseTransformerV2;
    4445import com.github.tomakehurst.wiremock.verification.LoggedRequest;
    4546
     
    6566
    6667    /**
    67      * {@link ResponseTransformer} for use with the WireMock server.
     68     * {@link ResponseTransformerV2} for use with the WireMock server.
    6869     * Current constructors supported:
    6970     * <ul>
     
    7374     * @return The transformers to instantiate
    7475     */
    75     Class<? extends ResponseTransformer>[] responseTransformers() default {};
     76    Class<? extends ResponseTransformerV2>[] responseTransformers() default {};
    7677
    7778    /**
     
    9293                    .orElseThrow(() -> new IllegalArgumentException("There must be a @BasicWiremock annotation"));
    9394            return context.getStore(namespace).getOrComputeIfAbsent(WireMockServer.class, clazz -> {
    94                 final List<ResponseTransformer> transformers = new ArrayList<>(annotation.responseTransformers().length);
    95                 for (Class<? extends ResponseTransformer> responseTransformer : annotation.responseTransformers()) {
     95                final List<ResponseTransformerV2> transformers = new ArrayList<>(annotation.responseTransformers().length);
     96                for (Class<? extends ResponseTransformerV2> responseTransformer : annotation.responseTransformers()) {
    9697                    for (Pair<Class<?>[], Object[]> parameterMapping : Arrays.asList(
    9798                            new Pair<>(new Class<?>[] {ExtensionContext.class }, new Object[] {context }),
    9899                            new Pair<>(new Class<?>[0], new Object[0]))) {
    99100                        try {
    100                             Constructor<? extends ResponseTransformer> constructor = responseTransformer
     101                            Constructor<? extends ResponseTransformerV2> constructor = responseTransformer
    101102                                    .getConstructor(parameterMapping.a);
    102103                            transformers.add(constructor.newInstance(parameterMapping.b));
     
    109110                return new WireMockServer(
    110111                    options().usingFilesUnderDirectory(Utils.isStripEmpty(annotation.value()) ? TestUtils.getTestDataRoot() :
    111                             annotation.value()).extensions(transformers.toArray(new ResponseTransformer[0])).dynamicPort());
     112                            annotation.value()).extensions(transformers.toArray(new ResponseTransformerV2[0])).dynamicPort());
    112113            }, WireMockServer.class);
    113114        }
     
    167168                for (Field field : wireMockFields) {
    168169                    if (WireMockServer.class.isAssignableFrom(field.getType())) {
    169                         final boolean isAccessible = field.isAccessible();
     170                        final boolean isAccessible = field.canAccess(context.getRequiredTestInstance());
    170171                        field.setAccessible(true);
    171172                        try {
     
    214215            }
    215216            super.beforeAll(context);
    216             Config.getPref().put("osm-server.url", getWiremock(context).baseUrl());
     217            Config.getPref().put("osm-server.url", getWiremock(context).baseUrl() + "/api");
     218            getWiremock(context).stubFor(WireMock.get("/api/0.6/capabilities")
     219                    .willReturn(WireMock.aResponse().withBodyFile("api/0.6/capabilities")));
     220            getWiremock(context).stubFor(WireMock.get("/api/capabilities")
     221                    .willReturn(WireMock.aResponse().withBodyFile("api/capabilities")));
    217222            OsmApi.getOsmApi().initialize(NullProgressMonitor.INSTANCE);
    218223        }
  • trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java

    r18811 r19056  
    1111import java.io.File;
    1212import java.io.IOException;
     13import java.io.InputStream;
    1314import java.util.ArrayList;
    1415import java.util.Arrays;
     
    2223import java.util.regex.Pattern;
    2324
     25import org.junit.jupiter.api.Test;
     26
    2427import net.trajano.commons.testing.UtilityClassTestUtil;
    25 import org.junit.jupiter.api.Test;
    2628
    2729/**
     
    354356     * Tests if readBytesFromStream handles null streams (might happen when there is no data on error stream)
    355357     * @throws IOException in case of I/O error
    356      */
    357     @Test
     358     * @deprecated {@link Utils#readBytesFromStream(InputStream)} is deprecated since the JVM has the same functionality.
     359     */
     360    @Test
     361    @Deprecated
    358362    void testNullStreamForReadBytesFromStream() throws IOException {
    359363        assertEquals(0, Utils.readBytesFromStream(null).length, "Empty on null stream");
Note: See TracChangeset for help on using the changeset viewer.