Skip to content

Commit 6113a4b

Browse files
committed
start some modernization
1 parent b4c4746 commit 6113a4b

File tree

7 files changed

+44
-34
lines changed

7 files changed

+44
-34
lines changed

src/test/java/org/htmlunit/DefaultCredentialsProvider2Test.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static org.junit.jupiter.api.Assertions.fail;
1818

1919
import java.io.StringWriter;
20+
import java.net.URI;
2021
import java.net.URL;
2122

2223
import org.apache.commons.lang3.StringUtils;
@@ -149,7 +150,7 @@ public void basicAuthenticationUserFromUrl() throws Exception {
149150

150151
try {
151152
// now a url with credentials
152-
final URL url = new URL("http://jetty:jetty@localhost:" + PORT + "/");
153+
final URL url = URI.create("http://jetty:jetty@localhost:" + PORT + "/").toURL();
153154
loadPageWithAlerts(html, url);
154155
if (!urlWithCredentials) {
155156
fail("Should not be authorized");
@@ -199,7 +200,7 @@ public void basicAuthenticationUserFromUrlUsedForNextSteps() throws Exception {
199200

200201
try {
201202
// now a url with credentials
202-
final URL url = new URL("http://jetty:jetty@localhost:" + PORT + "/");
203+
final URL url = URI.create("http://jetty:jetty@localhost:" + PORT + "/").toURL();
203204
loadPageWithAlerts(url);
204205
if (!urlWithCredentials) {
205206
fail("Should not be authorized");
@@ -263,7 +264,7 @@ public void basicAuthenticationUserFromUrlOverwrite() throws Exception {
263264

264265
try {
265266
// now a url with credentials
266-
final URL url = new URL("http://jetty:jetty@localhost:" + PORT + "/");
267+
final URL url = URI.create("http://jetty:jetty@localhost:" + PORT + "/").toURL();
267268
loadPageWithAlerts(url);
268269
if (!urlWithCredentials) {
269270
fail("Should not be authorized");
@@ -289,7 +290,7 @@ public void basicAuthenticationUserFromUrlOverwrite() throws Exception {
289290
}
290291

291292
try {
292-
final URL url = new URL("http://jetty:wrong@localhost:" + PORT + "/");
293+
final URL url = URI.create("http://jetty:wrong@localhost:" + PORT + "/").toURL();
293294
loadPage(html, url);
294295
fail("Should not be authorized");
295296
}
@@ -315,7 +316,7 @@ public void basicAuthenticationUserFromUrlOverwriteDefaultCredentials() throws E
315316
loadPageWithAlerts(URL_FIRST);
316317

317318
try {
318-
final URL url = new URL("http://joe:jetty@localhost:" + PORT + "/");
319+
final URL url = URI.create("http://joe:jetty@localhost:" + PORT + "/").toURL();
319320
final HtmlPage page = loadPage(html, url);
320321
fail("Should not be authorized");
321322
}
@@ -350,7 +351,7 @@ public void basicAuthenticationUserFromUrlOverwriteWrongDefaultCredentials() thr
350351

351352
try {
352353
// now a url with correct credentials
353-
final URL url = new URL("http://jetty:jetty@localhost:" + PORT + "/");
354+
final URL url = URI.create("http://jetty:jetty@localhost:" + PORT + "/").toURL();
354355
loadPageWithAlerts(url);
355356
if (!urlWithCredentials) {
356357
fail("Should not be authorized");

src/test/java/org/htmlunit/doc/DetailsTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package org.htmlunit.doc;
1616

1717
import java.io.IOException;
18+
import java.net.URI;
1819
import java.net.URL;
1920
import java.nio.charset.StandardCharsets;
2021
import java.util.ArrayList;
@@ -54,7 +55,7 @@ public class DetailsTest extends WebServerTestCase {
5455
*/
5556
@Test
5657
public void contentBlockingRequest() throws Exception {
57-
final URL url = new URL("http://localhost/");
58+
final URL url = URI.create("http://localhost/").toURL();
5859

5960
try (WebClient webClient = new WebClient()) {
6061
webClient.getOptions().setThrowExceptionOnScriptError(false);
@@ -154,7 +155,7 @@ protected WebResponse downloadResponse(final HttpUriRequest httpMethod,
154155
*/
155156
@Test
156157
public void contentBlockingFrames() throws Exception {
157-
final URL url = new URL("https://www.htmlunit.org/");
158+
final URL url = URI.create("https://www.htmlunit.org/").toURL();
158159

159160
try (WebClient webClient = new WebClient()) {
160161
// use our own FrameContentHandler

src/test/java/org/htmlunit/doc/FaqTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.awt.image.BufferedImage;
2020
import java.io.ByteArrayInputStream;
21+
import java.net.URI;
2122
import java.net.URL;
2223
import java.nio.charset.StandardCharsets;
2324

@@ -107,7 +108,7 @@ public void checkSvgSupport() throws Exception {
107108
*/
108109
@Test
109110
public void scriptPreProcessor() throws Exception {
110-
final URL url = new URL("https://www.htmlunit.org");
111+
final URL url = URI.create("https://www.htmlunit.org").toURL();
111112

112113
// create a ScriptPreProcessor
113114
final ScriptPreProcessor myScriptPreProcessor = new ScriptPreProcessor() {

src/test/java/org/htmlunit/html/HtmlAnchorTest.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static java.nio.charset.StandardCharsets.UTF_8;
1818

1919
import java.io.InputStream;
20+
import java.net.URI;
2021
import java.net.URL;
2122
import java.net.URLEncoder;
2223
import java.util.Collections;
@@ -765,12 +766,13 @@ public void click_refererHeader() throws Exception {
765766

766767
expandExpectedAlertsVariables(URL_FIRST);
767768

768-
final URL indexUrl = new URL(URL_FIRST.toString() + "index.html");
769+
final URL indexUrl = URI.create(URL_FIRST.toString() + "index.html").toURL();
769770

770771
getMockWebConnection().setResponse(indexUrl, firstContent);
771772
getMockWebConnection().setResponse(URL_SECOND, secondContent);
772773

773-
final WebDriver driver = loadPage2(firstContent, new URL(URL_FIRST.toString() + "index.html?test#ref"));
774+
final WebDriver driver =
775+
loadPage2(firstContent, URI.create(URL_FIRST.toString() + "index.html?test#ref").toURL());
774776
driver.findElement(By.id("link")).click();
775777

776778
assertEquals(2, getMockWebConnection().getRequestCount());
@@ -794,12 +796,13 @@ public void click_refererHeaderNoReferrer() throws Exception {
794796
+ "<body></body>\n"
795797
+ "</html>";
796798

797-
final URL indexUrl = new URL(URL_FIRST.toString() + "index.html");
799+
final URL indexUrl = URI.create(URL_FIRST.toString() + "index.html").toURL();
798800

799801
getMockWebConnection().setResponse(indexUrl, firstContent);
800802
getMockWebConnection().setResponse(URL_SECOND, secondContent);
801803

802-
final WebDriver driver = loadPage2(firstContent, new URL(URL_FIRST.toString() + "index.html?test#ref"));
804+
final WebDriver driver =
805+
loadPage2(firstContent, URI.create(URL_FIRST.toString() + "index.html?test#ref").toURL());
803806
driver.findElement(By.id("link")).click();
804807

805808
assertEquals(2, getMockWebConnection().getRequestCount());
@@ -823,12 +826,13 @@ public void click_refererHeaderNoReferrerCaseSensitive() throws Exception {
823826
+ "<body></body>\n"
824827
+ "</html>";
825828

826-
final URL indexUrl = new URL(URL_FIRST.toString() + "index.html");
829+
final URL indexUrl = URI.create(URL_FIRST.toString() + "index.html").toURL();
827830

828831
getMockWebConnection().setResponse(indexUrl, firstContent);
829832
getMockWebConnection().setResponse(URL_SECOND, secondContent);
830833

831-
final WebDriver driver = loadPage2(firstContent, new URL(URL_FIRST.toString() + "index.html?test#ref"));
834+
final WebDriver driver =
835+
loadPage2(firstContent, URI.create(URL_FIRST.toString() + "index.html?test#ref").toURL());
832836
driver.findElement(By.id("link")).click();
833837

834838
assertEquals(2, getMockWebConnection().getRequestCount());
@@ -856,12 +860,13 @@ public void controlClick_refererHeader() throws Exception {
856860

857861
expandExpectedAlertsVariables(URL_FIRST);
858862

859-
final URL indexUrl = new URL(URL_FIRST.toString() + "index.html");
863+
final URL indexUrl = URI.create(URL_FIRST.toString() + "index.html").toURL();
860864

861865
getMockWebConnection().setResponse(indexUrl, firstContent);
862866
getMockWebConnection().setResponse(URL_SECOND, secondContent);
863867

864-
final WebDriver driver = loadPage2(firstContent, new URL(URL_FIRST.toString() + "index.html?test#ref"));
868+
final WebDriver driver =
869+
loadPage2(firstContent, URI.create(URL_FIRST.toString() + "index.html?test#ref").toURL());
865870
new Actions(driver)
866871
.keyDown(Keys.CONTROL)
867872
.click(driver.findElement(By.id("link")))

src/test/java/org/htmlunit/javascript/host/dom/Document2Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
package org.htmlunit.javascript.host.dom;
1616

17-
import java.net.URL;
17+
import java.net.URI;
1818

1919
import org.htmlunit.MockWebConnection;
2020
import org.htmlunit.WebDriverTestCase;
@@ -375,7 +375,7 @@ public void activeElement_iframe() throws Exception {
375375
+ "</html>";
376376
getMockWebConnection().setDefaultResponse("Error: not found", 404, "Not Found", MimeType.TEXT_HTML);
377377

378-
getMockWebConnection().setResponse(new URL("http://example.com/frame1.html"), "");
378+
getMockWebConnection().setResponse(URI.create("http://example.com/frame1.html").toURL(), "");
379379

380380
final WebDriver driver = loadPage2(html);
381381

src/test/java/org/htmlunit/javascript/host/html/HTMLDocument2Test.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
package org.htmlunit.javascript.host.html;
1616

17+
import java.net.URI;
1718
import java.net.URL;
1819
import java.util.ArrayList;
1920
import java.util.List;
@@ -55,7 +56,7 @@ public void domain() throws Exception {
5556
+ "<body onload='doTest()'>\n"
5657
+ "</body></html>";
5758

58-
loadPageWithAlerts(html, new URL("http://www.gargoylesoftware.com/"), null);
59+
loadPageWithAlerts(html, URI.create("http://www.gargoylesoftware.com/").toURL(), null);
5960
}
6061

6162
/**
@@ -76,7 +77,7 @@ public void domainFromLocalhost() throws Exception {
7677
+ "</body></html>";
7778

7879
getMockWebConnection().setDefaultResponse(html);
79-
loadPageWithAlerts(html, new URL("http://localhost"), null);
80+
loadPageWithAlerts(html, URI.create("http://localhost").toURL(), null);
8081
}
8182

8283
/**
@@ -85,7 +86,7 @@ public void domainFromLocalhost() throws Exception {
8586
@Test
8687
@Alerts({"www.gargoylesoftware.com", "gargoylesoftware.com"})
8788
public void domainMixedCaseNetscape() throws Exception {
88-
final URL urlGargoyleUpperCase = new URL("http://WWW.GARGOYLESOFTWARE.COM/");
89+
final URL urlGargoyleUpperCase = URI.create("http://WWW.GARGOYLESOFTWARE.COM/").toURL();
8990

9091
final String html = DOCTYPE_HTML
9192
+ "<html><head><title>foo</title><script>\n"
@@ -119,7 +120,7 @@ public void domainMixedCase() throws Exception {
119120
+ "<body onload='doTest()'>\n"
120121
+ "</body></html>";
121122

122-
loadPageWithAlerts(html, new URL("http://www.gargoylesoftware.com/"), null);
123+
loadPageWithAlerts(html, URI.create("http://www.gargoylesoftware.com/").toURL(), null);
123124
}
124125

125126
/**
@@ -142,7 +143,7 @@ public void domainLong() throws Exception {
142143
+ "</body></html>";
143144

144145
getMockWebConnection().setDefaultResponse(html);
145-
loadPageWithAlerts(html, new URL("http://d4.d3.d2.d1.gargoylesoftware.com"), null);
146+
loadPageWithAlerts(html, URI.create("http://d4.d3.d2.d1.gargoylesoftware.com").toURL(), null);
146147
}
147148

148149
/**
@@ -163,7 +164,7 @@ public void domainSetSelf() throws Exception {
163164
+ "</body></html>";
164165

165166
getMockWebConnection().setDefaultResponse(html);
166-
loadPageWithAlerts(html, new URL("http://localhost"), null);
167+
loadPageWithAlerts(html, URI.create("http://localhost").toURL(), null);
167168
}
168169

169170
/**
@@ -214,7 +215,7 @@ public void domain_set_for_about_blank() throws Exception {
214215
+ "<iframe src='about:blank'></iframe>\n"
215216
+ "</body></html>";
216217

217-
loadPageWithAlerts(html, new URL("http://www.gargoylesoftware.com/"), null);
218+
loadPageWithAlerts(html, URI.create("http://www.gargoylesoftware.com/").toURL(), null);
218219
}
219220

220221
/**

src/test/java/org/htmlunit/javascript/host/html/HTMLDocumentTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static java.nio.charset.StandardCharsets.UTF_8;
1919
import static org.junit.jupiter.api.Assertions.fail;
2020

21+
import java.net.URI;
2122
import java.net.URL;
2223
import java.text.ParseException;
2324
import java.text.SimpleDateFormat;
@@ -2448,7 +2449,7 @@ public void baseURI_noBaseTag_urlPath() throws Exception {
24482449
+ "</body></html>";
24492450

24502451
expandExpectedAlertsVariables(URL_FIRST);
2451-
final URL url = new URL(URL_FIRST.toString() + "details/abc");
2452+
final URL url = URI.create(URL_FIRST.toString() + "details/abc").toURL();
24522453
final WebDriver driver = loadPage2(html, url);
24532454
verifyTitle2(driver, getExpectedAlerts());
24542455
if (driver instanceof HtmlUnitDriver && !"undefined".equals(getExpectedAlerts()[0])) {
@@ -2473,7 +2474,7 @@ public void baseURI_noBaseTag_urlParams() throws Exception {
24732474
+ "</body></html>";
24742475

24752476
expandExpectedAlertsVariables(URL_FIRST);
2476-
final URL url = new URL(URL_FIRST.toString() + "?x=y&z=zz");
2477+
final URL url = URI.create(URL_FIRST.toString() + "?x=y&z=zz").toURL();
24772478
final WebDriver driver = loadPage2(html, url);
24782479
verifyTitle2(driver, getExpectedAlerts());
24792480
if (driver instanceof HtmlUnitDriver && !"undefined".equals(getExpectedAlerts()[0])) {
@@ -2497,7 +2498,7 @@ public void baseURI_noBaseTag_urlPathAndParams() throws Exception {
24972498
+ "</script>\n"
24982499
+ "</body></html>";
24992500

2500-
final URL url = new URL(URL_FIRST.toString() + "details/abc;jsessionid=42?x=y&z=zz");
2501+
final URL url = URI.create(URL_FIRST.toString() + "details/abc;jsessionid=42?x=y&z=zz").toURL();
25012502
expandExpectedAlertsVariables(URL_FIRST);
25022503
final WebDriver driver = loadPage2(html, url);
25032504
verifyTitle2(driver, getExpectedAlerts());
@@ -2565,7 +2566,7 @@ public void baseURI_withBaseTag_absolutePath() throws Exception {
25652566
+ "</body></html>";
25662567

25672568
expandExpectedAlertsVariables(URL_FIRST);
2568-
loadPage2(html, new URL("http://localhost:" + PORT + "/path/to/page.html"));
2569+
loadPage2(html, URI.create("http://localhost:" + PORT + "/path/to/page.html").toURL());
25692570
verifyTitle2(getWebDriver(), getExpectedAlerts());
25702571
}
25712572

@@ -2588,7 +2589,7 @@ public void baseURI_withBaseTag_relativePath() throws Exception {
25882589
+ "</body></html>";
25892590

25902591
expandExpectedAlertsVariables(URL_FIRST);
2591-
loadPage2(html, new URL("http://localhost:" + PORT + "/path/to/page.html"));
2592+
loadPage2(html, URI.create("http://localhost:" + PORT + "/path/to/page.html").toURL());
25922593
verifyTitle2(getWebDriver(), getExpectedAlerts());
25932594
}
25942595

@@ -2611,7 +2612,7 @@ public void baseURI_withBaseTag_relativePath_slash() throws Exception {
26112612
+ "</body></html>";
26122613

26132614
expandExpectedAlertsVariables(URL_FIRST);
2614-
loadPage2(html, new URL("http://localhost:" + PORT + "/path/to/page.html"));
2615+
loadPage2(html, URI.create("http://localhost:" + PORT + "/path/to/page.html").toURL());
26152616
verifyTitle2(getWebDriver(), getExpectedAlerts());
26162617
}
26172618

@@ -2634,7 +2635,7 @@ public void baseURI_withBaseTag_relativePath_parent() throws Exception {
26342635
+ "</body></html>";
26352636

26362637
expandExpectedAlertsVariables(URL_FIRST);
2637-
loadPage2(html, new URL("http://localhost:" + PORT + "/path/to/page.html"));
2638+
loadPage2(html, URI.create("http://localhost:" + PORT + "/path/to/page.html").toURL());
26382639
verifyTitle2(getWebDriver(), getExpectedAlerts());
26392640
}
26402641

@@ -2657,7 +2658,7 @@ public void baseURI_withBaseTag_relativePath_strange() throws Exception {
26572658
+ "</body></html>";
26582659

26592660
expandExpectedAlertsVariables(URL_FIRST);
2660-
loadPage2(html, new URL("http://localhost:" + PORT + "/path/to/page.html"));
2661+
loadPage2(html, URI.create("http://localhost:" + PORT + "/path/to/page.html").toURL());
26612662
verifyTitle2(getWebDriver(), getExpectedAlerts());
26622663
}
26632664

0 commit comments

Comments
 (0)