diff --git a/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java b/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java index 07b5efff3d..11b91e61c2 100644 --- a/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java +++ b/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java @@ -9,9 +9,14 @@ import java.net.URL; import java.net.UnknownHostException; import java.util.TimeZone; +import java.util.function.Supplier; +import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.openstreetmap.josm.io.ChangesetClosedException; import org.openstreetmap.josm.io.IllegalDataException; import org.openstreetmap.josm.io.MissingOAuthAccessTokenException; @@ -49,35 +54,46 @@ public void setUp() throws Exception { DateUtils.PROP_ISO_DATES.put(Boolean.TRUE); } + static Stream testExplainBadRequest() { + return Stream.of( + Arguments.of((Supplier) () -> "The OSM server '"+baseUrl+"' reported a bad request.
", + new OsmApiException("")), + Arguments.of((Supplier) () -> "The OSM server '"+baseUrl+"' reported a bad request.

"+ + "Error message(untranslated): header", new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "")), + Arguments.of((Supplier) () -> "The OSM server '"+baseUrl+"' reported a bad request.

"+ + "Error message(untranslated): header", + new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", "invalid_url")), + Arguments.of((Supplier) () -> "The OSM server '"+host+"' reported a bad request.

"+ + "Error message(untranslated): header", + (Supplier) () -> new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", baseUrl)), + Arguments.of((Supplier) () -> "The OSM server '"+baseUrl+"' reported a bad request.

"+ + "The area you tried to download is too big or your request was too large.
"+ + "Either request a smaller area or use an export file provided by the OSM community." + + "

Downloading a smaller area is recommended!" + + "

Advanced users can use one of the following options:
", + new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "The maximum bbox", "")), + Arguments.of((Supplier) () -> "The OSM server '"+baseUrl+"' reported a bad request.

"+ + "The area you tried to download is too big or your request was too large.
"+ + "Either request a smaller area or use an export file provided by the OSM community." + + "

Downloading a smaller area is recommended!" + + "

Advanced users can use one of the following options:
", + new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "You requested too many nodes", "")) + ); + } /** * Test of {@link ExceptionUtil#explainBadRequest} method. */ - @Test - void testExplainBadRequest() { - assertEquals("The OSM server '"+baseUrl+"' reported a bad request.
", - ExceptionUtil.explainBadRequest(new OsmApiException(""))); - - assertEquals("The OSM server '"+baseUrl+"' reported a bad request.

"+ - "Error message(untranslated): header", - ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", ""))); - - assertEquals("The OSM server '"+baseUrl+"' reported a bad request.

"+ - "Error message(untranslated): header", - ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", "invalid_url"))); - - assertEquals("The OSM server '"+host+"' reported a bad request.

"+ - "Error message(untranslated): header", - ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "header", "", baseUrl))); - - assertEquals("The OSM server '"+baseUrl+"' reported a bad request.

"+ - "The area you tried to download is too big or your request was too large.
"+ - "Either request a smaller area or use an export file provided by the OSM community.", - ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "The maximum bbox", ""))); - - assertEquals("The OSM server '"+baseUrl+"' reported a bad request.

"+ - "The area you tried to download is too big or your request was too large.
"+ - "Either request a smaller area or use an export file provided by the OSM community.", - ExceptionUtil.explainBadRequest(new OsmApiException(HttpURLConnection.HTTP_BAD_REQUEST, "You requested too many nodes", ""))); + @ParameterizedTest(name = "{1}") + @MethodSource + @SuppressWarnings("unchecked") + void testExplainBadRequest(Supplier message, Object exception) { + assertEquals(message.get(), ExceptionUtil.explainBadRequest(exception instanceof Supplier ? ((Supplier) exception).get() : (OsmApiException) exception)); } /**