/*		
 * (C) Copyright 2017 Boni Garcia (http://bonigarcia.github.io/)		
 *		
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *		
 */
package io.github.bonigarcia.wdm.test.proxy;

import static io.github.bonigarcia.wdm.WebDriverManager.chromedriver;
import static java.lang.invoke.MethodHandles.lookup;
import static org.junit.Assert.assertTrue;
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockserver.integration.ClientAndServer;
//import org.mockserver.integration.ClientAndProxy;
import org.slf4j.Logger;

/**
 * Test for proxy with mock server.
 * 
 * @since 1.7.2
 */
@RunWith(MockitoJUnitRunner.class)
public class MockProxyTest {

    final Logger log = getLogger(lookup().lookupClass());

    private ClientAndServer proxy;
    private int proxyPort = 1080;

    @Before
    public void setup() throws IOException {
        chromedriver().clearDriverCache();
        log.debug("Starting mock proxy on port {}", proxyPort);
        proxy = startClientAndServer(proxyPort);
    }

    @After
    public void teardown() {
        log.debug("Stopping mock proxy on port {}", proxyPort);
        proxy.stop();
    }

    @Test
    public void testMockProx() throws MalformedURLException {
        chromedriver().proxy("localhost:" + proxyPort).proxyUser("")
                .proxyPass("")
                .driverRepositoryUrl(
                        new URL("https://chromedriver.storage.googleapis.com/"))
                .setup();
        File driver = new File(chromedriver().getDownloadedDriverPath());
        assertTrue(driver.exists());
    }

}
@@ -1080,32 +1080,63 @@
 dURLException;%0D%0A
+import java.net.ServerSocket;%0D%0A
 import java.net.
@@ -1165,16 +1165,21 @@
 it.After
+Class
 ;%0D%0Aimpor
@@ -1196,16 +1196,21 @@
 t.Before
+Class
 ;%0D%0Aimpor
@@ -1582,16 +1582,23 @@
 %0D%0A%0D%0A    
+static 
 final Lo
@@ -1658,16 +1658,23 @@
 private 
+static 
 ClientAn
@@ -1701,16 +1701,23 @@
 private 
+static 
 int prox
@@ -1725,15 +1725,8 @@
 Port
- = 1080
 ;%0D%0A%0D
@@ -1737,16 +1737,21 @@
  @Before
+Class
 %0D%0A    pu
@@ -1751,24 +1751,31 @@
 %0A    public 
+static 
 void setup()
@@ -1837,24 +1837,154 @@
 erCache();%0D%0A
+        try (ServerSocket serverSocket = new ServerSocket(0)) %7B%0D%0A            proxyPort = serverSocket.getLocalPort();%0D%0A        %7D%0D%0A
         log.
@@ -2105,16 +2105,21 @@
   @After
+Class
 %0D%0A    pu
@@ -2119,24 +2119,31 @@
 %0A    public 
+static 
 void teardow

Change setup and teardown of proxy test