aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhoelzlwimmerf <hoelzlwimmerf@Desktop01.fritz.box>2015-10-18 13:12:50 +0200
committerhoelzlwimmerf <hoelzlwimmerf@Desktop01.fritz.box>2015-10-18 13:12:50 +0200
commite316510734c3e986f89155e0a3916ae6c5167395 (patch)
tree9dc87965837b137b31bdee54777a8f038187634f
parenta44f729b5ab5a37eced813b1447de1fe19047e7a (diff)
downloadnanohttpd-e316510734c3e986f89155e0a3916ae6c5167395.tar.gz
Added ServerSocketFactory JUnit test
-rw-r--r--core/src/main/java/fi/iki/elonen/NanoHTTPD.java2
-rw-r--r--core/src/test/java/fi/iki/elonen/ServerSocketFactoryTest.java75
2 files changed, 76 insertions, 1 deletions
diff --git a/core/src/main/java/fi/iki/elonen/NanoHTTPD.java b/core/src/main/java/fi/iki/elonen/NanoHTTPD.java
index 52598e5..676f8f7 100644
--- a/core/src/main/java/fi/iki/elonen/NanoHTTPD.java
+++ b/core/src/main/java/fi/iki/elonen/NanoHTTPD.java
@@ -2088,7 +2088,7 @@ public abstract class NanoHTTPD {
* if the socket is in use.
*/
public void start(final int timeout, boolean daemon) throws IOException {
- this.myServerSocket = this.serverSocketFactory.create();
+ this.myServerSocket = this.getServerSocketFactory().create();
this.myServerSocket.setReuseAddress(true);
ServerRunnable serverRunnable = createServerRunnable(timeout);
diff --git a/core/src/test/java/fi/iki/elonen/ServerSocketFactoryTest.java b/core/src/test/java/fi/iki/elonen/ServerSocketFactoryTest.java
new file mode 100644
index 0000000..17b6913
--- /dev/null
+++ b/core/src/test/java/fi/iki/elonen/ServerSocketFactoryTest.java
@@ -0,0 +1,75 @@
+package fi.iki.elonen;
+
+/*
+ * #%L
+ * NanoHttpd-Core
+ * %%
+ * Copyright (C) 2012 - 2015 nanohttpd
+ * %%
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the nanohttpd nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * #L%
+ */
+
+import java.io.IOException;
+import java.net.ServerSocket;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ServerSocketFactoryTest extends NanoHTTPD {
+
+ public static final int PORT = 8192;
+
+ public ServerSocketFactoryTest() {
+ super(PORT);
+
+ this.setServerSocketFactory(new TestFactory());
+ }
+
+ @Test
+ public void isCustomServerSocketFactory() {
+ Assert.assertTrue(this.getServerSocketFactory() instanceof TestFactory);
+ }
+
+ @Test
+ public void testCreateServerSocket() {
+ ServerSocket ss = this.getServerSocketFactory().create();
+ Assert.assertTrue(ss != null);
+ }
+
+ private class TestFactory implements ServerSocketFactory {
+
+ @Override
+ public ServerSocket create() {
+ try {
+ return new ServerSocket();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+ }
+}