1818import static org .junit .jupiter .api .Assertions .fail ;
1919
2020import java .net .InetAddress ;
21+ import java .net .URI ;
2122import java .net .URL ;
2223import java .net .UnknownHostException ;
2324import java .nio .charset .StandardCharsets ;
@@ -71,28 +72,28 @@ public class CookieManager4Test extends WebDriverTestCase {
7172 @ BeforeAll
7273 public static void checkSettings () throws Exception {
7374 try {
74- InetAddress .getByName (new URL (URL_HOST1 ).getHost ());
75+ InetAddress .getByName (URI . create (URL_HOST1 ).getHost ());
7576 }
7677 catch (final UnknownHostException e ) {
7778 fail ("Host configuration '" + URL_HOST1 + "' is not present" );
7879 }
7980
8081 try {
81- InetAddress .getByName (new URL (URL_HOST2 ).getHost ());
82+ InetAddress .getByName (URI . create (URL_HOST2 ).getHost ());
8283 }
8384 catch (final UnknownHostException e ) {
8485 fail ("Host configuration '" + URL_HOST2 + "' is not present" );
8586 }
8687
8788 try {
88- InetAddress .getByName (new URL (URL_HOST3 ).getHost ());
89+ InetAddress .getByName (URI . create (URL_HOST3 ).getHost ());
8990 }
9091 catch (final UnknownHostException e ) {
9192 fail ("Host configuration '" + URL_HOST3 + "' is not present" );
9293 }
9394
9495 try {
95- InetAddress .getByName (new URL (URL_HOST4 ).getHost ());
96+ InetAddress .getByName (URI . create (URL_HOST4 ).getHost ());
9697 }
9798 catch (final UnknownHostException e ) {
9899 fail ("Host configuration '" + URL_HOST4 + "' is not present" );
@@ -135,7 +136,7 @@ public void domain() throws Exception {
135136 getMockWebConnection ().setDefaultResponse (CookieManagerTest .HTML_ALERT_COOKIE , 200 , "Ok" ,
136137 MimeType .TEXT_HTML , responseHeader );
137138
138- final URL firstUrl = new URL (URL_HOST1 );
139+ final URL firstUrl = URI . create (URL_HOST1 ). toURL ( );
139140 loadPage2 (firstUrl , StandardCharsets .ISO_8859_1 );
140141 verifyTitle2 (getWebDriver (), getExpectedAlerts ());
141142 }
@@ -198,7 +199,7 @@ public void storedDomain1() throws Exception {
198199 getMockWebConnection ().setDefaultResponse (CookieManagerTest .HTML_ALERT_COOKIE , 200 , "Ok" ,
199200 MimeType .TEXT_HTML , responseHeader );
200201
201- final WebDriver driver = loadPage2 (new URL (URL_HOST1 ), StandardCharsets .ISO_8859_1 );
202+ final WebDriver driver = loadPage2 (URI . create (URL_HOST1 ). toURL ( ), StandardCharsets .ISO_8859_1 );
202203 verifyTitle2 (driver , getExpectedAlerts ()[0 ]);
203204
204205 assertEquals (getExpectedAlerts ()[1 ], driver .manage ().getCookieNamed ("c1" ).toString ());
@@ -244,7 +245,7 @@ public void storedDomain2() throws Exception {
244245 getMockWebConnection ().setDefaultResponse (CookieManagerTest .HTML_ALERT_COOKIE , 200 , "Ok" ,
245246 MimeType .TEXT_HTML , responseHeader );
246247
247- final WebDriver driver = loadPage2 (new URL (URL_HOST2 ), StandardCharsets .ISO_8859_1 );
248+ final WebDriver driver = loadPage2 (URI . create (URL_HOST2 ). toURL ( ), StandardCharsets .ISO_8859_1 );
248249 verifyTitle2 (driver , getExpectedAlerts ()[0 ]);
249250
250251 assertEquals (getExpectedAlerts ()[1 ], driver .manage ().getCookieNamed ("c1" ).toString ());
@@ -288,7 +289,7 @@ public void storedDomain3() throws Exception {
288289 getMockWebConnection ().setDefaultResponse (CookieManagerTest .HTML_ALERT_COOKIE , 200 , "Ok" ,
289290 MimeType .TEXT_HTML , responseHeader );
290291
291- final WebDriver driver = loadPage2 (new URL (URL_HOST3 ), StandardCharsets .ISO_8859_1 );
292+ final WebDriver driver = loadPage2 (URI . create (URL_HOST3 ). toURL ( ), StandardCharsets .ISO_8859_1 );
292293 verifyTitle2 (driver , getExpectedAlerts ()[0 ]);
293294
294295 assertEquals (getExpectedAlerts ()[1 ], driver .manage ().getCookieNamed ("c1" ).toString ());
@@ -331,7 +332,7 @@ public void storedDomain4() throws Exception {
331332 getMockWebConnection ().setDefaultResponse (CookieManagerTest .HTML_ALERT_COOKIE , 200 , "Ok" ,
332333 MimeType .TEXT_HTML , responseHeader );
333334
334- final WebDriver driver = loadPage2 (new URL (URL_HOST4 ), StandardCharsets .ISO_8859_1 );
335+ final WebDriver driver = loadPage2 (URI . create (URL_HOST4 ). toURL ( ), StandardCharsets .ISO_8859_1 );
335336 verifyTitle2 (driver , getExpectedAlerts ()[0 ]);
336337
337338 assertEquals (getExpectedAlerts ()[1 ], driver .manage ().getCookieNamed ("c12" ).toString ());
@@ -389,7 +390,7 @@ public void storedDomainFromJs1() throws Exception {
389390 + "</body>\n "
390391 + "</html>" ;
391392
392- final WebDriver driver = loadPage2 (html , new URL (URL_HOST1 ));
393+ final WebDriver driver = loadPage2 (html , URI . create (URL_HOST1 ). toURL ( ));
393394 verifyTitle2 (driver );
394395
395396 assertEquals (4 , driver .manage ().getCookies ().size ());
@@ -437,7 +438,7 @@ public void storedDomainFromJs2() throws Exception {
437438 + "</body>\n "
438439 + "</html>" ;
439440
440- final WebDriver driver = loadPage2 (html , new URL (URL_HOST2 ));
441+ final WebDriver driver = loadPage2 (html , URI . create (URL_HOST2 ). toURL ( ));
441442 verifyTitle2 (driver );
442443
443444 assertEquals (2 , driver .manage ().getCookies ().size ());
@@ -483,7 +484,7 @@ public void storedDomainFromJs3() throws Exception {
483484 + "</body>\n "
484485 + "</html>" ;
485486
486- final WebDriver driver = loadPage2 (html , new URL (URL_HOST3 ));
487+ final WebDriver driver = loadPage2 (html , URI . create (URL_HOST3 ). toURL ( ));
487488 verifyTitle2 (driver );
488489
489490 assertEquals (2 , driver .manage ().getCookies ().size ());
@@ -532,7 +533,7 @@ public void storedDomainFromJs4() throws Exception {
532533 + "</body>\n "
533534 + "</html>" ;
534535
535- final WebDriver driver = loadPage2 (html , new URL (URL_HOST4 ));
536+ final WebDriver driver = loadPage2 (html , URI . create (URL_HOST4 ). toURL ( ));
536537 verifyTitle2 (driver );
537538
538539 final String [] expected = getExpectedAlerts ();
@@ -555,7 +556,7 @@ public void domainDuplicate() throws Exception {
555556 getMockWebConnection ().setDefaultResponse (CookieManagerTest .HTML_ALERT_COOKIE , 200 , "Ok" ,
556557 MimeType .TEXT_HTML , responseHeader );
557558
558- final URL firstUrl = new URL (URL_HOST1 );
559+ final URL firstUrl = URI . create (URL_HOST1 ). toURL ( );
559560
560561 loadPage2 (firstUrl , StandardCharsets .ISO_8859_1 );
561562 verifyTitle2 (getWebDriver (), getExpectedAlerts ());
@@ -573,7 +574,7 @@ public void domainDuplicateLeadingDot() throws Exception {
573574 getMockWebConnection ().setDefaultResponse (CookieManagerTest .HTML_ALERT_COOKIE , 200 , "Ok" ,
574575 MimeType .TEXT_HTML , responseHeader );
575576
576- final URL firstUrl = new URL (URL_HOST1 );
577+ final URL firstUrl = URI . create (URL_HOST1 ). toURL ( );
577578
578579 loadPage2 (firstUrl , StandardCharsets .ISO_8859_1 );
579580 verifyTitle2 (getWebDriver (), getExpectedAlerts ());
@@ -598,7 +599,7 @@ public void domainDuplicateLeadingDotSend() throws Exception {
598599 final WebDriver webDriver = getWebDriver ();
599600 webDriver .manage ().deleteAllCookies ();
600601
601- loadPageWithAlerts2 (new URL (URL_HOST1 ));
602+ loadPageWithAlerts2 (URI . create (URL_HOST1 ). toURL ( ));
602603 WebRequest lastRequest = getMockWebConnection ().getLastWebRequest ();
603604 assertNull (lastRequest .getAdditionalHeaders ().get (HttpHeader .COOKIE ));
604605
@@ -626,14 +627,14 @@ public void domainDuplicateLeadingDotRedirect() throws Exception {
626627 getMockWebConnection ().setDefaultResponse (html , 200 , "Ok" , MimeType .TEXT_HTML , responseHeader );
627628
628629 responseHeader .add (new NameValuePair ("Location" , URL_HOST1 + "next.html" ));
629- getMockWebConnection ().setResponse (new URL (URL_HOST1 ), "redirect" , 301 , "Ok" , MimeType .TEXT_HTML ,
630+ getMockWebConnection ().setResponse (URI . create (URL_HOST1 ). toURL ( ), "redirect" , 301 , "Ok" , MimeType .TEXT_HTML ,
630631 responseHeader );
631632
632633 final WebDriver webDriver = getWebDriver ();
633634 webDriver .manage ().deleteAllCookies ();
634635
635636 final int startCount = getMockWebConnection ().getRequestCount ();
636- loadPageWithAlerts2 (new URL (URL_HOST1 ));
637+ loadPageWithAlerts2 (URI . create (URL_HOST1 ). toURL ( ));
637638 assertEquals (2 , getMockWebConnection ().getRequestCount () - startCount );
638639 final WebRequest lastRequest = getMockWebConnection ().getLastWebRequest ();
639640 assertEquals ("c1=1; c2=2" , lastRequest .getAdditionalHeaders ().get (HttpHeader .COOKIE ));
@@ -664,7 +665,7 @@ public void domain2() throws Exception {
664665 + "</html>" ;
665666
666667 getMockWebConnection ().setDefaultResponse (CookieManagerTest .HTML_ALERT_COOKIE );
667- final URL firstUrl = new URL (URL_HOST1 );
668+ final URL firstUrl = URI . create (URL_HOST1 ). toURL ( );
668669 getMockWebConnection ().setResponse (firstUrl , html , 200 , "Ok" , MimeType .TEXT_HTML , responseHeader1 );
669670
670671 loadPage2 (firstUrl , StandardCharsets .ISO_8859_1 );
@@ -696,7 +697,7 @@ public void domain3() throws Exception {
696697 + "</html>" ;
697698
698699 getMockWebConnection ().setDefaultResponse (CookieManagerTest .HTML_ALERT_COOKIE );
699- final URL firstUrl = new URL (URL_HOST3 );
700+ final URL firstUrl = URI . create (URL_HOST3 ). toURL ( );
700701 getMockWebConnection ().setResponse (firstUrl , html , 200 , "Ok" , MimeType .TEXT_HTML , responseHeader1 );
701702
702703 loadPage2 (firstUrl , StandardCharsets .ISO_8859_1 );
@@ -724,7 +725,7 @@ public void differentHostsSameDomain() throws Exception {
724725 + "</html>" ;
725726
726727 getMockWebConnection ().setDefaultResponse (CookieManagerTest .HTML_ALERT_COOKIE );
727- final URL firstUrl = new URL (URL_HOST1 );
728+ final URL firstUrl = URI . create (URL_HOST1 ). toURL ( );
728729 getMockWebConnection ().setResponse (firstUrl , html , 200 , "Ok" , MimeType .TEXT_HTML , responseHeader1 );
729730
730731 loadPage2 (firstUrl , StandardCharsets .ISO_8859_1 );
@@ -751,7 +752,7 @@ public void differentHostsSameDomainCookieFromJS() throws Exception {
751752 + "</html>" ;
752753
753754 getMockWebConnection ().setDefaultResponse (CookieManagerTest .HTML_ALERT_COOKIE );
754- final URL firstUrl = new URL (URL_HOST1 );
755+ final URL firstUrl = URI . create (URL_HOST1 ). toURL ( );
755756 getMockWebConnection ().setResponse (firstUrl , html );
756757
757758 loadPage2 (firstUrl , StandardCharsets .ISO_8859_1 );
@@ -778,7 +779,7 @@ public void differentHostsSameDomainCookieFromMeta() throws Exception {
778779 + "</html>" ;
779780
780781 getMockWebConnection ().setDefaultResponse (CookieManagerTest .HTML_ALERT_COOKIE );
781- final URL firstUrl = new URL (URL_HOST1 );
782+ final URL firstUrl = URI . create (URL_HOST1 ). toURL ( );
782783 getMockWebConnection ().setResponse (firstUrl , html );
783784
784785 loadPage2 (firstUrl , StandardCharsets .ISO_8859_1 );
@@ -802,7 +803,7 @@ private void testCookies(final URL url, final String cookie1, final String cooki
802803 @ Test
803804 @ Alerts ("key1=\" Hi there\" ; key2=Howdy" )
804805 public void unqualifiedHost () throws Exception {
805- testCookies (new URL (URL_HOST4 ), "key1=\" Hi there\" " , "key2=Howdy" );
806+ testCookies (URI . create (URL_HOST4 ). toURL ( ), "key1=\" Hi there\" " , "key2=Howdy" );
806807 }
807808
808809 /**
@@ -811,7 +812,7 @@ public void unqualifiedHost() throws Exception {
811812 @ Test
812813 @ Alerts ("key1=\" Hi there\" ; key2=Howdy" )
813814 public void fullyQualifiedHost () throws Exception {
814- testCookies (new URL (URL_HOST1 ), "key1=\" Hi there\" " , "key2=Howdy" );
815+ testCookies (URI . create (URL_HOST1 ). toURL ( ), "key1=\" Hi there\" " , "key2=Howdy" );
815816 }
816817
817818 /**
@@ -831,10 +832,10 @@ public void sameSite() throws Exception {
831832 responseHeader .add (new NameValuePair ("Set-Cookie" , "c7=stRiCT; SameSite=stRiCT" ));
832833
833834 getMockWebConnection ().setDefaultResponse ("" );
834- getMockWebConnection ().setResponse (new URL (URL_HOST1 ), HTML_ALERT_COOKIE ,
835+ getMockWebConnection ().setResponse (URI . create (URL_HOST1 ). toURL ( ), HTML_ALERT_COOKIE ,
835836 200 , "OK" , MimeType .TEXT_HTML , responseHeader );
836837
837- final WebDriver driver = loadPage2 (new URL (URL_HOST1 ), StandardCharsets .ISO_8859_1 );
838+ final WebDriver driver = loadPage2 (URI . create (URL_HOST1 ). toURL ( ), StandardCharsets .ISO_8859_1 );
838839 verifyTitle2 (driver , getExpectedAlerts ());
839840 driver .get (URL_HOST1 + "foo" );
840841
@@ -881,10 +882,10 @@ public void sameSiteOtherSubdomain() throws Exception {
881882 responseHeader .add (new NameValuePair ("Set-Cookie" , "c5=unknown; SameSite=unknown" ));
882883
883884 getMockWebConnection ().setDefaultResponse ("" );
884- getMockWebConnection ().setResponse (new URL (URL_HOST1 ), HTML_ALERT_COOKIE ,
885+ getMockWebConnection ().setResponse (URI . create (URL_HOST1 ). toURL ( ), HTML_ALERT_COOKIE ,
885886 200 , "OK" , MimeType .TEXT_HTML , responseHeader );
886887
887- final WebDriver driver = loadPage2 (new URL (URL_HOST1 ), StandardCharsets .ISO_8859_1 );
888+ final WebDriver driver = loadPage2 (URI . create (URL_HOST1 ). toURL ( ), StandardCharsets .ISO_8859_1 );
888889 verifyTitle2 (driver , getExpectedAlerts ());
889890 driver .get (URL_HOST2 + "foo" );
890891
@@ -911,10 +912,10 @@ public void sameSiteOriginOtherSubdomain() throws Exception {
911912 responseHeader .add (new NameValuePair ("Set-Cookie" , "c5=unknown; SameSite=unknown" ));
912913
913914 getMockWebConnection ().setDefaultResponse ("" );
914- getMockWebConnection ().setResponse (new URL (URL_HOST1 ), HTML_ALERT_COOKIE ,
915+ getMockWebConnection ().setResponse (URI . create (URL_HOST1 ). toURL ( ), HTML_ALERT_COOKIE ,
915916 200 , "OK" , MimeType .TEXT_HTML , responseHeader );
916917
917- final WebDriver driver = loadPage2 (new URL (URL_HOST1 ), StandardCharsets .ISO_8859_1 );
918+ final WebDriver driver = loadPage2 (URI . create (URL_HOST1 ). toURL ( ), StandardCharsets .ISO_8859_1 );
918919 verifyTitle2 (driver , getExpectedAlerts ());
919920 driver .get (URL_HOST2 + "foo" );
920921 driver .get (URL_HOST1 + "foo" );
@@ -964,12 +965,12 @@ public void sameSiteIncludeFromSameDomain() throws Exception {
964965 + "<body>\n "
965966 + "</body></html>" ;
966967 getMockWebConnection ().setDefaultResponse ("" );
967- getMockWebConnection ().setResponse (new URL (URL_HOST1 ), HTML_ALERT_COOKIE ,
968+ getMockWebConnection ().setResponse (URI . create (URL_HOST1 ). toURL ( ), HTML_ALERT_COOKIE ,
968969 200 , "OK" , MimeType .TEXT_HTML , responseHeader );
969- getMockWebConnection ().setResponse (new URL (URL_HOST1 + "include" ), html ,
970+ getMockWebConnection ().setResponse (URI . create (URL_HOST1 + "include" ). toURL ( ), html ,
970971 200 , "OK" , MimeType .TEXT_HTML , responseHeader );
971972
972- final WebDriver driver = loadPage2 (new URL (URL_HOST1 ), StandardCharsets .ISO_8859_1 );
973+ final WebDriver driver = loadPage2 (URI . create (URL_HOST1 ). toURL ( ), StandardCharsets .ISO_8859_1 );
973974 verifyTitle2 (driver , getExpectedAlerts ());
974975 driver .get (URL_HOST1 + "include" );
975976
@@ -1019,12 +1020,12 @@ public void sameSiteIncludeFromSubDomain() throws Exception {
10191020 + "<body>\n "
10201021 + "</body></html>" ;
10211022 getMockWebConnection ().setDefaultResponse ("" );
1022- getMockWebConnection ().setResponse (new URL (URL_HOST1 ), HTML_ALERT_COOKIE ,
1023+ getMockWebConnection ().setResponse (URI . create (URL_HOST1 ). toURL ( ), HTML_ALERT_COOKIE ,
10231024 200 , "OK" , MimeType .TEXT_HTML , responseHeader );
1024- getMockWebConnection ().setResponse (new URL (URL_HOST2 ), html ,
1025+ getMockWebConnection ().setResponse (URI . create (URL_HOST2 ). toURL ( ), html ,
10251026 200 , "OK" , MimeType .TEXT_HTML , responseHeader );
10261027
1027- final WebDriver driver = loadPage2 (new URL (URL_HOST1 ), StandardCharsets .ISO_8859_1 );
1028+ final WebDriver driver = loadPage2 (URI . create (URL_HOST1 ). toURL ( ), StandardCharsets .ISO_8859_1 );
10281029 verifyTitle2 (driver , getExpectedAlerts ());
10291030 driver .get (URL_HOST2 );
10301031
@@ -1074,12 +1075,12 @@ public void sameSiteIFrameFromSameDomain() throws Exception {
10741075 + "<iframe src='" + URL_HOST1 + "iframe.html'></iframe>\n "
10751076 + "</body></html>" ;
10761077 getMockWebConnection ().setDefaultResponse ("" );
1077- getMockWebConnection ().setResponse (new URL (URL_HOST1 ), HTML_ALERT_COOKIE ,
1078+ getMockWebConnection ().setResponse (URI . create (URL_HOST1 ). toURL ( ), HTML_ALERT_COOKIE ,
10781079 200 , "OK" , MimeType .TEXT_HTML , responseHeader );
1079- getMockWebConnection ().setResponse (new URL (URL_HOST1 + "include" ), html ,
1080+ getMockWebConnection ().setResponse (URI . create (URL_HOST1 + "include" ). toURL ( ), html ,
10801081 200 , "OK" , MimeType .TEXT_HTML , responseHeader );
10811082
1082- final WebDriver driver = loadPage2 (new URL (URL_HOST1 ), StandardCharsets .ISO_8859_1 );
1083+ final WebDriver driver = loadPage2 (URI . create (URL_HOST1 ). toURL ( ), StandardCharsets .ISO_8859_1 );
10831084 verifyTitle2 (driver , getExpectedAlerts ());
10841085 driver .get (URL_HOST1 + "include" );
10851086
@@ -1129,12 +1130,12 @@ public void sameSiteIFrameFromSubDomain() throws Exception {
11291130 + "<iframe src='" + URL_HOST1 + "iframe.html'></iframe>\n "
11301131 + "</body></html>" ;
11311132 getMockWebConnection ().setDefaultResponse ("" );
1132- getMockWebConnection ().setResponse (new URL (URL_HOST1 ), HTML_ALERT_COOKIE ,
1133+ getMockWebConnection ().setResponse (URI . create (URL_HOST1 ). toURL ( ), HTML_ALERT_COOKIE ,
11331134 200 , "OK" , MimeType .TEXT_HTML , responseHeader );
1134- getMockWebConnection ().setResponse (new URL (URL_HOST2 + "include" ), html ,
1135+ getMockWebConnection ().setResponse (URI . create (URL_HOST2 + "include" ). toURL ( ), html ,
11351136 200 , "OK" , MimeType .TEXT_HTML , responseHeader );
11361137
1137- final WebDriver driver = loadPage2 (new URL (URL_HOST1 ), StandardCharsets .ISO_8859_1 );
1138+ final WebDriver driver = loadPage2 (URI . create (URL_HOST1 ). toURL ( ), StandardCharsets .ISO_8859_1 );
11381139 verifyTitle2 (driver , getExpectedAlerts ());
11391140 driver .get (URL_HOST2 + "include" );
11401141
@@ -1196,7 +1197,7 @@ public void issue270() throws Exception {
11961197 + "</script></body>\n "
11971198 + "</html>" ;
11981199
1199- final URL firstUrl = new URL (URL_HOST1 );
1200+ final URL firstUrl = URI . create (URL_HOST1 ). toURL ( );
12001201 getMockWebConnection ().setResponse (firstUrl , html );
12011202 loadPage2 (html , firstUrl );
12021203
0 commit comments