Skip to content

Commit 1d50807

Browse files
committed
fix HttpUrlSourceTest test
1 parent 6da9650 commit 1d50807

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.io.ByteArrayOutputStream;
1212
import java.util.Arrays;
1313

14+
import static com.danikula.videocache.ProxyCacheUtils.DEFAULT_BUFFER_SIZE;
1415
import static com.danikula.videocache.support.ProxyCacheTestUtils.ASSETS_DATA_BIG_NAME;
1516
import static com.danikula.videocache.support.ProxyCacheTestUtils.ASSETS_DATA_NAME;
1617
import static com.danikula.videocache.support.ProxyCacheTestUtils.HTTP_DATA_BIG_SIZE;
@@ -83,7 +84,7 @@ public void testFetchDataWithRedirect() throws Exception {
8384
HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL_ONE_REDIRECT);
8485
source.open(0);
8586
byte[] readData = new byte[HTTP_DATA_SIZE];
86-
source.read(readData);
87+
readSource(source, readData);
8788
source.close();
8889

8990
byte[] expectedData = Arrays.copyOfRange(loadAssetFile(ASSETS_DATA_NAME), 0, HTTP_DATA_SIZE);
@@ -96,7 +97,7 @@ public void testFetchPartialDataWithRedirect() throws Exception {
9697
HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL_ONE_REDIRECT);
9798
source.open(offset);
9899
byte[] readData = new byte[HTTP_DATA_SIZE - offset];
99-
source.read(readData);
100+
readSource(source, readData);
100101
source.close();
101102

102103
byte[] expectedData = Arrays.copyOfRange(loadAssetFile(ASSETS_DATA_NAME), offset, HTTP_DATA_SIZE);
@@ -109,7 +110,7 @@ public void testFetchPartialDataWithMultiRedirects() throws Exception {
109110
HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL_3_REDIRECTS);
110111
source.open(offset);
111112
byte[] readData = new byte[HTTP_DATA_SIZE - offset];
112-
source.read(readData);
113+
readSource(source, readData);
113114
source.close();
114115

115116
byte[] expectedData = Arrays.copyOfRange(loadAssetFile(ASSETS_DATA_NAME), offset, HTTP_DATA_SIZE);
@@ -130,4 +131,14 @@ public void testMimeByUrl() throws Exception {
130131
assertThat(new HttpUrlSource("http://mysite.by/video.mp4").getMime()).isEqualTo("video/mp4");
131132
assertThat(new HttpUrlSource(HTTP_DATA_URL).getMime()).isEqualTo("image/jpeg");
132133
}
134+
135+
private void readSource(Source source, byte[] target) throws ProxyCacheException {
136+
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
137+
int totalRead = 0;
138+
int readBytes;
139+
while ((readBytes = source.read(buffer)) != -1) {
140+
System.arraycopy(buffer, 0, target, totalRead, readBytes);
141+
totalRead += readBytes;
142+
}
143+
}
133144
}

0 commit comments

Comments
 (0)