package org.webbitserver.netty;

import java.util.Set;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class NettyWebServerTest {
    @Test
    public void stopsServerCleanlyNotLeavingResourcesHanging() throws Exception {
        int threadCountStart = getCurrentThreadCount();

        // Build, start, wait and stop the Netty Web Server
        new NettyWebServer(8080).start().stop();

        assertEquals(threadCountStart, getCurrentThreadCount());
    }

    private int getCurrentThreadCount() {
        Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
        Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]);
        return threadArray.length;
    }

}
@@ -48,16 +48,56 @@
 il.Set;%0A
+import java.util.concurrent.Executors;%0A%0A
 import o
@@ -340,25 +340,24 @@
 ount();%0A
-%0A
         
 // Build
@@ -352,67 +352,31 @@
     
-// Build, start, wait and stop the 
 Netty
- 
 Web
- 
 Server
-%0A       
+ server =
  new
@@ -395,21 +395,150 @@
 ver(
-8080).start()
+Executors.newSingleThreadScheduledExecutor(), 8080).start();%0A        assertEquals(threadCountStart+1, getCurrentThreadCount());%0A        server
 .sto
@@ -542,17 +542,16 @@
 stop();%0A
-%0A
         

Add another assertion to verify that thread count is incremented by one