Changeset 19226 in josm
- Timestamp:
- 2024-09-19T14:33:38+02:00 (2 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java
r18870 r19226 10 10 import java.net.UnknownHostException; 11 11 import java.util.TimeZone; 12 import java.util.function.Supplier; 13 import java.util.stream.Stream; 12 14 13 15 import org.junit.jupiter.api.BeforeEach; 14 16 import org.junit.jupiter.api.Test; 17 import org.junit.jupiter.params.ParameterizedTest; 18 import org.junit.jupiter.params.provider.Arguments; 19 import org.junit.jupiter.params.provider.MethodSource; 15 20 import org.openstreetmap.josm.io.ChangesetClosedException; 16 21 import org.openstreetmap.josm.io.IllegalDataException; … … 50 55 } 51 56 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 } 52 89 /** 53 90 * Test of {@link ExceptionUtil#explainBadRequest} method. 54 91 */ 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)); 81 97 } 82 98
Note:
See TracChangeset
for help on using the changeset viewer.