Skip to content

Commit 0ef820d

Browse files
committed
fail faster
1 parent d44f44e commit 0ef820d

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

src/test/java/org/htmlunit/CookieManager4Test.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,4 +1151,15 @@ public void sameSiteIFrameFromSubDomain() throws Exception {
11511151
assertEquals("unknown", mgr.getCookie("c5").getSameSite());
11521152
}
11531153
}
1154+
1155+
@Override
1156+
protected final WebDriver getWebDriver() {
1157+
final WebDriver driver = super.getWebDriver();
1158+
if (driver instanceof HtmlUnitDriver) {
1159+
// set timeout to fail fast when the url not mapped
1160+
((HtmlUnitDriver) driver).getWebClient().getOptions().setTimeout(1000);
1161+
}
1162+
1163+
return driver;
1164+
}
11541165
}

src/test/java/org/htmlunit/CookieManager5Test.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,25 @@ public void updateCookieExpires() throws Exception {
172172
servlets.put(SetCookieExpires1000Servlet.URL, SetCookieExpires1000Servlet.class);
173173
startWebServer("./", null, servlets);
174174

175-
final WebClient webClient = getWebClient();
176-
webClient.getPage("http://localhost:" + PORT + SetCookieExpires10Servlet.URL);
177-
assertEquals(1, webClient.getCookieManager().getCookies().size());
178-
Cookie cookie = webClient.getCookieManager().getCookies().iterator().next();
179-
assertFalse("" + cookie.getExpires(), cookie.getExpires().after(date));
180-
181-
webClient.getPage("http://localhost:" + PORT + SetCookieExpires1000Servlet.URL);
182-
assertEquals(1, webClient.getCookieManager().getCookies().size());
183-
cookie = webClient.getCookieManager().getCookies().iterator().next();
184-
assertTrue("" + cookie.getExpires(), cookie.getExpires().after(date));
175+
try (WebClient webClient = getWebClient()) {
176+
webClient.getPage("http://localhost:" + PORT + SetCookieExpires10Servlet.URL);
177+
assertEquals(1, webClient.getCookieManager().getCookies().size());
178+
Cookie cookie = webClient.getCookieManager().getCookies().iterator().next();
179+
assertFalse("" + cookie.getExpires(), cookie.getExpires().after(date));
180+
181+
webClient.getPage("http://localhost:" + PORT + SetCookieExpires1000Servlet.URL);
182+
assertEquals(1, webClient.getCookieManager().getCookies().size());
183+
cookie = webClient.getCookieManager().getCookies().iterator().next();
184+
assertTrue("" + cookie.getExpires(), cookie.getExpires().after(date));
185+
}
186+
}
187+
188+
@Override
189+
protected WebClient getWebClient() {
190+
final WebClient webClient = super.getWebClient();
191+
// set timeout to fail fast when the url not mapped
192+
webClient.getOptions().setTimeout(1000);
193+
return webClient;
185194
}
186195

187196
/**

src/test/java/org/htmlunit/WebServerTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ protected SslConnectionFactory getSslConnectionFactory() {
493493
* Returns the WebClient instance for the current test with the current {@link BrowserVersion}.
494494
* @return a WebClient with the current {@link BrowserVersion}
495495
*/
496-
protected final WebClient getWebClient() {
496+
protected WebClient getWebClient() {
497497
if (webClient_ == null) {
498498
webClient_ = new WebClient(getBrowserVersion());
499499
webClient_.setAlertHandler(alertHandler_);

0 commit comments

Comments
 (0)