Code example for ServerSocket

Methods: getLocalPort, setSoTimeout

0
@TestTargetClass(HttpURLConnection.class) 
public class HttpURLConnectionTest extends TestCase {
 
    private final static Object bound = new Object();
 
    static class MockServer extends Thread {
        ServerSocket serverSocket;
        boolean accepted = false;
        boolean started = false;
 
        public MockServer(String name) throws IOException {
            super(name);
            serverSocket = new ServerSocket(0);
            serverSocket.setSoTimeout(1000);
        } 
 
        public int port() { 
            return serverSocket.getLocalPort();
        } 
 
        @Override