Changeset 19226 in josm for trunk/test/unit


Ignore:
Timestamp:
2024-09-19T14:33:38+02:00 (3 months ago)
Author:
taylor.smock
Message:

Update tests for r19225

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java

    r18870 r19226  
    1010import java.net.UnknownHostException;
    1111import java.util.TimeZone;
     12import java.util.function.Supplier;
     13import java.util.stream.Stream;
    1214
    1315import org.junit.jupiter.api.BeforeEach;
    1416import org.junit.jupiter.api.Test;
     17import org.junit.jupiter.params.ParameterizedTest;
     18import org.junit.jupiter.params.provider.Arguments;
     19import org.junit.jupiter.params.provider.MethodSource;
    1520import org.openstreetmap.josm.io.ChangesetClosedException;
    1621import org.openstreetmap.josm.io.IllegalDataException;
     
    5055    }
    5156
     57    static Stream<Arguments> testExplainBadRequest() {
     58        return Stream.of(
     59                Arguments.of((Supplier<String>) () -> "<html>The OSM server '"+baseUrl+"' reported a bad request.<br></html>",
     60                        new OsmApiException("")),
     61                Arguments.of((Supplier<String>) () -> "<html>The OSM server '"+baseUrl+"' reported a bad request.<br><br>"+
     62                        "Error message(untranslated): header</html>", new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "")),
     63                Arguments.of((Supplier<String>) () -> "<html>The OSM server '"+baseUrl+"' reported a bad request.<br><br>"+
     64                        "Error message(untranslated): header</html>",
     65                        new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", "invalid_url")),
     66                Arguments.of((Supplier<String>) () -> "<html>The OSM server '"+host+"' reported a bad request.<br><br>"+
     67                        "Error message(untranslated): header</html>",
     68                        (Supplier<OsmApiException>) () -> new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", baseUrl)),
     69                Arguments.of((Supplier<String>) () -> "<html>The OSM server '"+baseUrl+"' reported a bad request.<br><br>"+
     70                        "The area you tried to download is too big or your request was too large.<br>"+
     71                        "Either request a smaller area or use an export file provided by the OSM community." +
     72                        "<br><br>Downloading a smaller area is <em>recommended</em>!" +
     73                        "<br><br>Advanced users can use one of the following options:<br><ul>" +
     74                        "<li><a href=\"https://josm.openstreetmap.de/wiki/Help/Action/Download#DownloadfromOverpassAPI\">Overpass</a></li>" +
     75                        "<li><a href=\"https://www.geofabrik.de/data/download.html\">Geofabrik</a></li>" +
     76                        "<li><a href=\"https://planet.openstreetmap.org/\">OSM Planet File</a></li></ul></html>",
     77                        new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "The maximum bbox", "")),
     78                Arguments.of((Supplier<String>) () -> "<html>The OSM server '"+baseUrl+"' reported a bad request.<br><br>"+
     79                        "The area you tried to download is too big or your request was too large.<br>"+
     80                        "Either request a smaller area or use an export file provided by the OSM community." +
     81                        "<br><br>Downloading a smaller area is <em>recommended</em>!" +
     82                        "<br><br>Advanced users can use one of the following options:<br><ul>" +
     83                        "<li><a href=\"https://josm.openstreetmap.de/wiki/Help/Action/Download#DownloadfromOverpassAPI\">Overpass</a></li>" +
     84                        "<li><a href=\"https://www.geofabrik.de/data/download.html\">Geofabrik</a></li>" +
     85                        "<li><a href=\"https://planet.openstreetmap.org/\">OSM Planet File</a></li></ul></html>",
     86                        new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "You requested too many nodes", ""))
     87        );
     88    }
    5289    /**
    5390     * Test of {@link ExceptionUtil#explainBadRequest} method.
    5491     */
    55     @Test
    56     void testExplainBadRequest() {
    57         assertEquals("<html>The OSM server '"+baseUrl+"' reported a bad request.<br></html>",
    58                 ExceptionUtil.explainBadRequest(new OsmApiException("")));
    59 
    60         assertEquals("<html>The OSM server '"+baseUrl+"' reported a bad request.<br><br>"+
    61                 "Error message(untranslated): header</html>",
    62                 ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "")));
    63 
    64         assertEquals("<html>The OSM server '"+baseUrl+"' reported a bad request.<br><br>"+
    65                 "Error message(untranslated): header</html>",
    66                 ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", "invalid_url")));
    67 
    68         assertEquals("<html>The OSM server '"+host+"' reported a bad request.<br><br>"+
    69                 "Error message(untranslated): header</html>",
    70                 ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", baseUrl)));
    71 
    72         assertEquals("<html>The OSM server '"+baseUrl+"' reported a bad request.<br><br>"+
    73                 "The area you tried to download is too big or your request was too large.<br>"+
    74                 "Either request a smaller area or use an export file provided by the OSM community.</html>",
    75                 ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "The maximum bbox", "")));
    76 
    77         assertEquals("<html>The OSM server '"+baseUrl+"' reported a bad request.<br><br>"+
    78                 "The area you tried to download is too big or your request was too large.<br>"+
    79                 "Either request a smaller area or use an export file provided by the OSM community.</html>",
    80                 ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "You requested too many nodes", "")));
     92    @ParameterizedTest(name = "{1}")
     93    @MethodSource
     94    @SuppressWarnings("unchecked")
     95    void testExplainBadRequest(Supplier<String> message, Object exception) {
     96        assertEquals(message.get(), ExceptionUtil.explainBadRequest(exception instanceof Supplier ? ((Supplier<OsmApiException>) exception).get() : (OsmApiException) exception));
    8197    }
    8298
Note: See TracChangeset for help on using the changeset viewer.