RoutingConfig { static void downloadOsmFile(String urlString, Path osmFile) { HttpURLConnection con; URL url; try { url = new URL(urlString); con = (HttpURLConnection) url.openConnection(); } catch (MalformedURLException e) { throw new RoutingEngineException("The OSM file URL is malformed", e); } catch (IOException e) { throw new RoutingEngineException("The OSM file cannot be downloaded", e); } try { con.setRequestMethod("GET"); } catch (ProtocolException e) { throw new IllegalStateException("Can't set request method", e); } con.setConnectTimeout(10000); con.setReadTimeout(10000); logger.info("Downloading OSM file from {}", urlString); try { Files.copy(con.getInputStream(), osmFile); } catch (IOException e) { throw new RoutingEngineException("OSM file download failed", e); } logger.info("File saved to {}", osmFile); } @Autowired  RoutingConfig(RoutingProperties routingProperties);   }
@Test void should_throw_exception_when_url_is_malformed() { Path osmFile = Mockito.mock(Path.class); String malformedUrl = "x+y"; assertThatExceptionOfType(RoutingEngineException.class) .isThrownBy(() -> RoutingConfig.downloadOsmFile(malformedUrl, osmFile)) .withMessageContaining("malformed"); }