// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static int getPort(HttpProxyCacheServer server) {
//     String proxyUrl = server.getProxyUrl("test");
//     Pattern pattern = Pattern.compile("http://127.0.0.1:(\\d*)/test");
//     Matcher matcher = pattern.matcher(proxyUrl);
//     assertThat(matcher.find()).isTrue();
//     String portAsString = matcher.group(1);
//     return Integer.parseInt(portAsString);
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static int getPortWithoutPing(HttpProxyCacheServer server) {
//     return (Integer) ReflectUtil.getField(server, "port");
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static void installExternalSystemProxy() {
//     // see proxies list at http://proxylist.hidemyass.com/
//     Proxy systemProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("162.8.230.7", 11180));
//     ProxySelector mockedProxySelector = Mockito.mock(ProxySelector.class);
//     when(mockedProxySelector.select(Mockito.<URI>any())).thenReturn(Lists.newArrayList(systemProxy));
//     ProxySelector.setDefault(mockedProxySelector);
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static void resetSystemProxy() {
//     ProxySelector mockedProxySelector = Mockito.mock(ProxySelector.class);
//     when(mockedProxySelector.select(Mockito.<URI>any())).thenReturn(Lists.newArrayList(Proxy.NO_PROXY));
//     ProxySelector.setDefault(mockedProxySelector);
// }


import org.junit.Before;
import org.junit.Test;
import org.robolectric.RuntimeEnvironment;
import java.io.ByteArrayOutputStream;
import java.net.Socket;
import static com.danikula.videocache.support.ProxyCacheTestUtils.getPort;
import static com.danikula.videocache.support.ProxyCacheTestUtils.getPortWithoutPing;
import static com.danikula.videocache.support.ProxyCacheTestUtils.installExternalSystemProxy;
import static com.danikula.videocache.support.ProxyCacheTestUtils.resetSystemProxy;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
package com.danikula.videocache;




/**
 * Tests {@link Pinger}.
 *
 * @author Alexey Danilov (danikula@gmail.com).
 */
public class PingerTest extends BaseTest {

    @Before
    public void setup() throws Exception {
        resetSystemProxy();
    }

    @Test
    public void testPingSuccess() throws Exception {
        HttpProxyCacheServer server = new HttpProxyCacheServer(RuntimeEnvironment.application);
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static int getPort(HttpProxyCacheServer server) {
//     String proxyUrl = server.getProxyUrl("test");
//     Pattern pattern = Pattern.compile("http://127.0.0.1:(\\d*)/test");
//     Matcher matcher = pattern.matcher(proxyUrl);
//     assertThat(matcher.find()).isTrue();
//     String portAsString = matcher.group(1);
//     return Integer.parseInt(portAsString);
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static int getPortWithoutPing(HttpProxyCacheServer server) {
//     return (Integer) ReflectUtil.getField(server, "port");
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static void installExternalSystemProxy() {
//     // see proxies list at http://proxylist.hidemyass.com/
//     Proxy systemProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("162.8.230.7", 11180));
//     ProxySelector mockedProxySelector = Mockito.mock(ProxySelector.class);
//     when(mockedProxySelector.select(Mockito.<URI>any())).thenReturn(Lists.newArrayList(systemProxy));
//     ProxySelector.setDefault(mockedProxySelector);
// }
// 
// Path: test/src/test/java/com/danikula/videocache/support/ProxyCacheTestUtils.java
// public static void resetSystemProxy() {
//     ProxySelector mockedProxySelector = Mockito.mock(ProxySelector.class);
//     when(mockedProxySelector.select(Mockito.<URI>any())).thenReturn(Lists.newArrayList(Proxy.NO_PROXY));
//     ProxySelector.setDefault(mockedProxySelector);
// }


// Path: test/src/test/java/com/danikula/videocache/PingerTest.java
import org.junit.Before;
import org.junit.Test;
import org.robolectric.RuntimeEnvironment;
import java.io.ByteArrayOutputStream;
import java.net.Socket;
import static com.danikula.videocache.support.ProxyCacheTestUtils.getPort;
import static com.danikula.videocache.support.ProxyCacheTestUtils.getPortWithoutPing;
import static com.danikula.videocache.support.ProxyCacheTestUtils.installExternalSystemProxy;
import static com.danikula.videocache.support.ProxyCacheTestUtils.resetSystemProxy;
import static org.fest.assertions.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

package com.danikula.videocache;




/**
 * Tests {@link Pinger}.
 *
 * @author Alexey Danilov (danikula@gmail.com).
 */
public class PingerTest extends BaseTest {

    @Before
    public void setup() throws Exception {
        resetSystemProxy();
    }

    @Test
    public void testPingSuccess() throws Exception {
        HttpProxyCacheServer server = new HttpProxyCacheServer(RuntimeEnvironment.application);
        Pinger pinger = new Pinger("127.0.0.1", getPort(server));