Changeset 17211 in josm


Ignore:
Timestamp:
2020-10-15T23:11:36+02:00 (6 days ago)
Author:
simon04
Message:

see #15102 - see #16637 - Fix HttpClientTest

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java

    r17197 r17211  
    1313import static org.hamcrest.CoreMatchers.is;
    1414import static org.hamcrest.CoreMatchers.nullValue;
     15import static org.hamcrest.CoreMatchers.startsWith;
    1516import static org.hamcrest.MatcherAssert.assertThat;
    1617import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase;
     
    2324import java.net.URL;
    2425import java.nio.charset.StandardCharsets;
     26import java.nio.file.Files;
     27import java.nio.file.Path;
     28import java.nio.file.Paths;
    2529import java.util.Collections;
    2630import java.util.Map;
     
    3034import java.util.stream.Collectors;
    3135
    32 import org.junit.Assert;
    3336import org.junit.Before;
    3437import org.junit.Rule;
     
    339342    @Test
    340343    public void testOpenUrlGzip() throws IOException {
    341         final byte[] gpx = Utils.readBytesFromStream(getClass().getClassLoader().getResourceAsStream("tracks/tracks.gpx.gz"));
     344        final Path path = Paths.get(TestUtils.getTestDataRoot(), "tracks/tracks.gpx.gz");
     345        final byte[] gpx = Files.readAllBytes(path);
    342346        localServer.stubFor(get(urlEqualTo("/trace/1613906/data"))
    343347                .willReturn(aResponse()
     
    348352        final URL url = new URL(localServer.url("/trace/1613906/data"));
    349353        try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
    350             Assert.assertTrue(x.readLine().startsWith("<?xml version="));
     354            assertThat(x.readLine(), startsWith("<?xml version="));
    351355        }
    352356    }
     
    358362    @Test
    359363    public void testOpenUrlBzip() throws IOException {
    360         final byte[] gpx = Utils.readBytesFromStream(getClass().getClassLoader().getResourceAsStream("tracks/tracks.gpx.bz2"));
     364        final Path path = Paths.get(TestUtils.getTestDataRoot(), "tracks/tracks.gpx.bz2");
     365        final byte[] gpx = Files.readAllBytes(path);
    361366        localServer.stubFor(get(urlEqualTo("/trace/785544/data"))
    362367                .willReturn(aResponse()
     
    367372        final URL url = new URL(localServer.url("/trace/785544/data"));
    368373        try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
    369             Assert.assertTrue(x.readLine().startsWith("<?xml version="));
     374            assertThat(x.readLine(), startsWith("<?xml version="));
    370375        }
    371376    }
     
    377382    @Test
    378383    public void testOpenUrlBzipAccordingToContentDisposition() throws IOException {
    379         final byte[] gpx = Utils.readBytesFromStream(getClass().getClassLoader().getResourceAsStream("tracks/tracks.gpx.bz2"));
     384        final Path path = Paths.get(TestUtils.getTestDataRoot(), "tracks/tracks.gpx.bz2");
     385        final byte[] gpx = Files.readAllBytes(path);
    380386        localServer.stubFor(get(urlEqualTo("/trace/1350010/data"))
    381387                .willReturn(aResponse()
     
    388394        try (BufferedReader x = HttpClient.create(url).connect()
    389395                .uncompress(true).uncompressAccordingToContentDisposition(true).getContentReader()) {
    390             Assert.assertTrue(x.readLine().startsWith("<?xml version="));
     396            assertThat(x.readLine(), startsWith("<?xml version="));
    391397        }
    392398    }
Note: See TracChangeset for help on using the changeset viewer.