Skip to content

Commit b2fcc28

Browse files
committed
simplify
1 parent 8dccfbe commit b2fcc28

File tree

3 files changed

+15
-40
lines changed

3 files changed

+15
-40
lines changed

src/test/java/org/htmlunit/HttpWebConnectionProxyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void setup() throws Exception {
4343
startWebServer("src/test/resources/testfiles/noproxyroot/");
4444

4545
final Server proxyWebServer = createWebServer(PORT_PROXY_SERVER,
46-
"src/test/resources/testfiles/proxyroot/", null, null, null);
46+
"src/test/resources/testfiles/proxyroot/", null, null);
4747
WebServerTestCase.tryStart(PORT_PROXY_SERVER, proxyWebServer);
4848
proxyWebServer_ = proxyWebServer;
4949

src/test/java/org/htmlunit/WebDriverTestCase.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,11 @@ protected boolean isBasicAuthentication() {
753753
*/
754754
protected static void startWebServer(final String resourceBase, final String[] classpath,
755755
final Map<String, Class<? extends Servlet>> servlets) throws Exception {
756-
startWebServer(resourceBase, classpath, servlets, null);
756+
stopWebServers();
757+
LAST_TEST_UsesMockWebConnection_ = Boolean.FALSE;
758+
759+
STATIC_SERVER_STARTER_ = ExceptionUtils.getStackTrace(new Throwable("StaticServerStarter"));
760+
STATIC_SERVER_ = WebServerTestCase.createWebServer(PORT, resourceBase, classpath, servlets);
757761
}
758762

759763
/**
@@ -773,27 +777,7 @@ protected static void startWebServer2(final String resourceBase, final String[]
773777
STATIC_SERVER2_.stop();
774778
}
775779
STATIC_SERVER2_STARTER_ = ExceptionUtils.getStackTrace(new Throwable("StaticServer2Starter"));
776-
STATIC_SERVER2_ = WebServerTestCase.createWebServer(PORT2, resourceBase, classpath, servlets, null);
777-
}
778-
779-
/**
780-
* Starts the web server on the default {@link #PORT}.
781-
* The given resourceBase is used to be the ROOT directory that serves the default context.
782-
* <p><b>Don't forget to stop the returned Server after the test</b>
783-
*
784-
* @param resourceBase the base of resources for the default context
785-
* @param classpath additional classpath entries to add (may be null)
786-
* @param servlets map of {String, Class} pairs: String is the path spec, while class is the class
787-
* @param handler wrapper for handler (can be null)
788-
* @throws Exception if the test fails
789-
*/
790-
protected static void startWebServer(final String resourceBase, final String[] classpath,
791-
final Map<String, Class<? extends Servlet>> servlets, final HandlerWrapper handler) throws Exception {
792-
stopWebServers();
793-
LAST_TEST_UsesMockWebConnection_ = Boolean.FALSE;
794-
795-
STATIC_SERVER_STARTER_ = ExceptionUtils.getStackTrace(new Throwable("StaticServerStarter"));
796-
STATIC_SERVER_ = WebServerTestCase.createWebServer(PORT, resourceBase, classpath, servlets, handler);
780+
STATIC_SERVER2_ = WebServerTestCase.createWebServer(PORT2, resourceBase, classpath, servlets);
797781
}
798782

799783
/**

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.eclipse.jetty.server.ServerConnector;
4040
import org.eclipse.jetty.server.SslConnectionFactory;
4141
import org.eclipse.jetty.server.handler.HandlerList;
42-
import org.eclipse.jetty.server.handler.HandlerWrapper;
4342
import org.eclipse.jetty.server.handler.ResourceHandler;
4443
import org.eclipse.jetty.servlet.DefaultServlet;
4544
import org.eclipse.jetty.util.security.Constraint;
@@ -52,8 +51,8 @@
5251
import org.junit.jupiter.api.AfterEach;
5352

5453
/**
55-
* A WebTestCase which starts a local server, and doens't use WebDriver.
56-
*
54+
* A WebTestCase which starts a local server, and doesn't use WebDriver.
55+
* <p>
5756
* <b>Note that {@link WebDriverTestCase} should be used unless HtmlUnit-specific feature
5857
* is needed and Selenium does not support it.</b>
5958
*
@@ -122,7 +121,7 @@ protected void startWebServer(final String resourceBase, final String[] classpat
122121

123122
/**
124123
* This is usually needed if you want to have a running server during many tests invocation.
125-
*
124+
* <p>
126125
* Creates and starts a web server on the default {@link #PORT}.
127126
* The given resourceBase is used to be the ROOT directory that serves the default context.
128127
* <p><b>Don't forget to stop the returned Server after the test</b>
@@ -133,12 +132,12 @@ protected void startWebServer(final String resourceBase, final String[] classpat
133132
* @throws Exception if an error occurs
134133
*/
135134
public static Server createWebServer(final String resourceBase, final String[] classpath) throws Exception {
136-
return createWebServer(PORT, resourceBase, classpath, null, null);
135+
return createWebServer(PORT, resourceBase, classpath, null);
137136
}
138137

139138
/**
140139
* This is usually needed if you want to have a running server during many tests invocation.
141-
*
140+
* <p>
142141
* Creates and starts a web server on the default {@link #PORT}.
143142
* The given resourceBase is used to be the ROOT directory that serves the default context.
144143
* <p><b>Don't forget to stop the returned Server after the test</b>
@@ -147,12 +146,11 @@ public static Server createWebServer(final String resourceBase, final String[] c
147146
* @param resourceBase the base of resources for the default context
148147
* @param classpath additional classpath entries to add (may be null)
149148
* @param servlets map of {String, Class} pairs: String is the path spec, while class is the class
150-
* @param handler wrapper for handler (can be null)
151149
* @return the newly created server
152150
* @throws Exception if an error occurs
153151
*/
154152
public static Server createWebServer(final int port, final String resourceBase, final String[] classpath,
155-
final Map<String, Class<? extends Servlet>> servlets, final HandlerWrapper handler) throws Exception {
153+
final Map<String, Class<? extends Servlet>> servlets) throws Exception {
156154

157155
final Server server = buildServer(port);
158156

@@ -181,13 +179,7 @@ public static Server createWebServer(final int port, final String resourceBase,
181179
}
182180
}
183181
context.setClassLoader(loader);
184-
if (handler != null) {
185-
handler.setHandler(context);
186-
server.setHandler(handler);
187-
}
188-
else {
189-
server.setHandler(context);
190-
}
182+
server.setHandler(context);
191183

192184
tryStart(port, server);
193185
return server;
@@ -407,8 +399,7 @@ public static void tryStart(final int port, final Server server) throws Exceptio
407399
}
408400
catch (final IOException e) {
409401
// looks like newer jetty already catches the bind exception
410-
final Throwable cause = e.getCause();
411-
if (cause != null && cause instanceof BindException) {
402+
if (e.getCause() instanceof BindException) {
412403
if (System.currentTimeMillis() > maxWait) {
413404
// destroy the server to free all associated resources
414405
server.stop();

0 commit comments

Comments
 (0)