Skip to content

Commit 7e48955

Browse files
committed
fix tests
1 parent 355e83b commit 7e48955

3 files changed

Lines changed: 10 additions & 20 deletions

File tree

library/src/main/java/com/danikula/videocache/IgnoreHostProxySelector.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ static void install(String hostToIgnore, int portToIgnore) {
4040
@Override
4141
public List<Proxy> select(URI uri) {
4242
boolean ignored = hostToIgnore.equals(uri.getHost()) && portToIgnore == uri.getPort();
43-
List<Proxy> proxies = ignored ? NO_PROXY_LIST : defaultProxySelector.select(uri);
44-
return proxies;
43+
return ignored ? NO_PROXY_LIST : defaultProxySelector.select(uri);
4544
}
4645

4746
@Override

test/src/test/java/com/danikula/videocache/HttpProxyCacheServerTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import com.danikula.videocache.support.ProxyCacheTestUtils;
1010
import com.danikula.videocache.support.Response;
1111

12-
import junit.framework.Assert;
13-
1412
import org.junit.Before;
1513
import org.junit.Test;
1614
import org.robolectric.RuntimeEnvironment;
@@ -33,7 +31,6 @@
3331
import static com.danikula.videocache.support.ProxyCacheTestUtils.HTTP_DATA_URL_ONE_REDIRECT;
3432
import static com.danikula.videocache.support.ProxyCacheTestUtils.getFileContent;
3533
import static com.danikula.videocache.support.ProxyCacheTestUtils.getPort;
36-
import static com.danikula.videocache.support.ProxyCacheTestUtils.getPortWithoutPing;
3734
import static com.danikula.videocache.support.ProxyCacheTestUtils.installExternalSystemProxy;
3835
import static com.danikula.videocache.support.ProxyCacheTestUtils.loadAssetFile;
3936
import static com.danikula.videocache.support.ProxyCacheTestUtils.readProxyResponse;
@@ -352,15 +349,15 @@ public void testWorkWithExternalProxy() throws Exception {
352349
assertThat(response.second.data).isEqualTo(loadAssetFile(ASSETS_DATA_NAME));
353350
}
354351

355-
@Test(expected = IOException.class) // https://github.com/danikula/AndroidVideoCache/issues/28
352+
@Test // https://github.com/danikula/AndroidVideoCache/issues/28
356353
public void testDoesNotWorkWithoutCustomProxySelector() throws Exception {
357354
HttpProxyCacheServer httpProxyCacheServer = new HttpProxyCacheServer(RuntimeEnvironment.application);
358355
// IgnoreHostProxySelector is set in HttpProxyCacheServer constructor. So let reset it by custom.
359356
installExternalSystemProxy();
360357

361-
String proxiedUrl = "http://127.0.0.1:" + getPortWithoutPing(httpProxyCacheServer) + "/" + HTTP_DATA_URL;
362-
readProxyResponse(httpProxyCacheServer, proxiedUrl);
363-
Assert.fail(); // should throw IOException on the previous line
358+
String proxiedUrl = httpProxyCacheServer.getProxyUrl(HTTP_DATA_URL);
359+
// server can't proxy this url due to it is not alive (can't ping itself), so it returns original url
360+
assertThat(proxiedUrl).isEqualTo(HTTP_DATA_URL);
364361
}
365362

366363
private Pair<File, Response> readProxyData(String url, int offset) throws IOException {
@@ -390,6 +387,6 @@ private HttpProxyCacheServer newProxy(File cacheDir) {
390387
}
391388

392389
private void waitForAsyncTrimming() throws InterruptedException {
393-
Thread.sleep(100);
390+
Thread.sleep(500);
394391
}
395392
}

test/src/test/java/com/danikula/videocache/PingerTest.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
package com.danikula.videocache;
22

3-
import junit.framework.Assert;
4-
53
import org.junit.Before;
64
import org.junit.Test;
75
import org.robolectric.RuntimeEnvironment;
86

97
import java.io.ByteArrayOutputStream;
10-
import java.io.IOException;
118
import java.net.Socket;
129

13-
import static com.danikula.videocache.support.ProxyCacheTestUtils.HTTP_DATA_URL;
1410
import static com.danikula.videocache.support.ProxyCacheTestUtils.getPort;
1511
import static com.danikula.videocache.support.ProxyCacheTestUtils.getPortWithoutPing;
1612
import static com.danikula.videocache.support.ProxyCacheTestUtils.installExternalSystemProxy;
17-
import static com.danikula.videocache.support.ProxyCacheTestUtils.readProxyResponse;
1813
import static com.danikula.videocache.support.ProxyCacheTestUtils.resetSystemProxy;
1914
import static org.fest.assertions.api.Assertions.assertThat;
2015
import static org.mockito.Mockito.mock;
@@ -75,14 +70,13 @@ public void testPingedWithExternalProxy() throws Exception {
7570
assertThat(pinger.ping(1, 100)).isTrue();
7671
}
7772

78-
@Test(expected = IOException.class) // https://github.com/danikula/AndroidVideoCache/issues/28
73+
@Test // https://github.com/danikula/AndroidVideoCache/issues/28
7974
public void testIsNotPingedWithoutCustomProxySelector() throws Exception {
80-
HttpProxyCacheServer httpProxyCacheServer = new HttpProxyCacheServer(RuntimeEnvironment.application);
75+
HttpProxyCacheServer server = new HttpProxyCacheServer(RuntimeEnvironment.application);
8176
// IgnoreHostProxySelector is set in HttpProxyCacheServer constructor. So let reset it by custom.
8277
installExternalSystemProxy();
8378

84-
String proxiedUrl = "http://127.0.0.1:" + getPortWithoutPing(httpProxyCacheServer) + "/" + HTTP_DATA_URL;
85-
readProxyResponse(httpProxyCacheServer, proxiedUrl);
86-
Assert.fail(); // should throw IOException on the previous line
79+
Pinger pinger = new Pinger("127.0.0.1", getPortWithoutPing(server));
80+
assertThat(pinger.ping(1, 100)).isFalse();
8781
}
8882
}

0 commit comments

Comments
 (0)