Skip to content

Commit 247da8e

Browse files
committed
Avoid using deprecated URL constructor
1 parent cb8ca44 commit 247da8e

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

documentation/src/docs/asciidoc/user-guide/writing-tests.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ integral types: `byte`, `short`, `int`, `long`, and their boxed counterparts.
16661666
| `java.math.BigDecimal` | `"123.456e789"` -> `new BigDecimal("123.456e789")`
16671667
| `java.math.BigInteger` | `"1234567890123456789"` -> `new BigInteger("1234567890123456789")`
16681668
| `java.net.URI` | `"https://junit.org/"` -> `URI.create("https://junit.org/")`
1669-
| `java.net.URL` | `"https://junit.org/"` -> `new URL("https://junit.org/")`
1669+
| `java.net.URL` | `"https://junit.org/"` -> `URI.create("https://junit.org/").toURL()`
16701670
| `java.nio.charset.Charset` | `"UTF-8"` -> `Charset.forName("UTF-8")`
16711671
| `java.nio.file.Path` | `"/path/to/file"` -> `Paths.get("/path/to/file")`
16721672
| `java.time.Duration` | `"PT3S"` -> `Duration.ofSeconds(3)`

documentation/src/test/java/example/session/HttpTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static org.junit.jupiter.api.Assertions.assertEquals;
1515

1616
import java.net.HttpURLConnection;
17+
import java.net.URI;
1718
import java.net.URL;
1819

1920
import org.junit.jupiter.api.Test;
@@ -24,7 +25,7 @@ class HttpTests {
2425
void respondsWith204() throws Exception {
2526
String host = System.getProperty("http.server.host"); // <1>
2627
String port = System.getProperty("http.server.port"); // <2>
27-
URL url = new URL("http://" + host + ":" + port + "/test");
28+
URL url = URI.create("http://" + host + ":" + port + "/test").toURL();
2829

2930
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
3031
connection.setRequestMethod("GET");

junit-jupiter-params/src/main/java/org/junit/jupiter/params/converter/DefaultArgumentConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ private static Class<?> toClass(String type) {
289289

290290
private static URL toURL(String url) {
291291
try {
292-
return new URL(url);
292+
return URI.create(url).toURL();
293293
}
294294
catch (MalformedURLException ex) {
295295
throw new ArgumentConversionException(

junit-jupiter-params/src/test/java/org/junit/jupiter/params/converter/DefaultArgumentConverterTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void convertsStringToURI() {
184184

185185
@Test
186186
void convertsStringToURL() throws Exception {
187-
assertConverts("https://junit.org/junit5", URL.class, new URL("https://junit.org/junit5"));
187+
assertConverts("https://junit.org/junit5", URL.class, URI.create("https://junit.org/junit5").toURL());
188188
}
189189

190190
// --- java.time -----------------------------------------------------------

0 commit comments

Comments
 (0)