Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/test/java/org/htmlunit/ScriptExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.htmlunit;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.PrintWriter;
Expand Down Expand Up @@ -53,12 +54,8 @@ public void constructor() throws Exception {
@Test
public void getPage() throws Exception {
final String html = DOCTYPE_HTML + "<html><script>notExisting()</script></html>";
try {
loadPage(html);
}
catch (final ScriptException e) {
assertEquals(URL_FIRST, e.getPage().getUrl());
}
final ScriptException e = assertThrows(ScriptException.class, () -> loadPage(html));
assertEquals(URL_FIRST, e.getPage().getUrl());
}

/**
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/org/htmlunit/WebClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,9 @@ public void redirectionSameURL() throws Exception {
final HtmlPage page1 = getPageWithRedirectionsSameURL(1);
assertEquals("Second", page1.getTitleText());

try {
getPageWithRedirectionsSameURL(30);
}
catch (final Exception e) {
assertTrue(e.getMessage(), e.getMessage().contains("Too many redirects"));
}
final FailingHttpStatusCodeException e = Assertions.assertThrows(FailingHttpStatusCodeException.class,
() -> getPageWithRedirectionsSameURL(30));
assertTrue(e.getMessage(), e.getMessage().contains("Too many redirects"));
}

private HtmlPage getPageWithRedirectionsSameURL(final int nbRedirections) throws Exception {
Expand Down
18 changes: 6 additions & 12 deletions src/test/java/org/htmlunit/javascript/JavaScriptEngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,9 @@ public void scriptErrorContainsPageUrl() throws Exception {
+ "</head><body>\n"
+ "</body></html>";

try {
loadPageWithAlerts(content1);
}
catch (final Exception e) {
assertTrue(e.getMessage().contains(URL_FIRST.toString()));
}
final ScriptException e1 = Assertions.assertThrows(ScriptException.class,
() -> loadPageWithAlerts(content1));
assertTrue(e1.getMessage().contains(URL_FIRST.toString()));

// external script
final WebClient client = getWebClient();
Expand All @@ -305,12 +302,9 @@ public void scriptErrorContainsPageUrl() throws Exception {
webConnection.setResponse(urlScript, jsContent, "text/javascript");
client.setWebConnection(webConnection);

try {
client.getPage(URL_FIRST);
}
catch (final Exception e) {
assertTrue(e.getMessage(), e.getMessage().contains(urlScript.toString()));
}
final ScriptException e2 = Assertions.assertThrows(ScriptException.class,
() -> client.getPage(URL_FIRST));
assertTrue(e2.getMessage(), e2.getMessage().contains(urlScript.toString()));
}

/**
Expand Down
Loading