fix HttpDownloaderTest after refactoring

HttpDownloaderTest doesn't get run in gitlab-ci since it was too flaky with
internet connections in the emulator.  So these were missed until I manually
ran the tests.

688057b3e7e214db49566b84d5b3dcd0db30dc2b
195aaae7e52dc1c47741965904ed17bdc816a71c
df08e84e7829652d7999eee5451080a012b00a1e
This commit is contained in:
Hans-Christoph Steiner 2018-04-18 20:29:27 +02:00
parent d917d6d007
commit 552da24d30

View File

@ -1,12 +1,12 @@
package org.fdroid.fdroid.net; package org.fdroid.fdroid.net;
import android.net.Uri;
import org.fdroid.fdroid.ProgressListener; import org.fdroid.fdroid.ProgressListener;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -31,9 +31,9 @@ public class HttpDownloaderTest {
@Test @Test
public void downloadUninterruptedTest() throws IOException, InterruptedException { public void downloadUninterruptedTest() throws IOException, InterruptedException {
for (String urlString : urls) { for (String urlString : urls) {
URL url = new URL(urlString); Uri uri = Uri.parse(urlString);
File destFile = File.createTempFile("dl-", ""); File destFile = File.createTempFile("dl-", "");
HttpDownloader httpDownloader = new HttpDownloader(url, destFile); HttpDownloader httpDownloader = new HttpDownloader(uri, destFile);
httpDownloader.download(); httpDownloader.download();
assertTrue(destFile.exists()); assertTrue(destFile.exists());
assertTrue(destFile.canRead()); assertTrue(destFile.canRead());
@ -46,12 +46,12 @@ public class HttpDownloaderTest {
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
String urlString = "https://f-droid.org/repo/index.jar"; String urlString = "https://f-droid.org/repo/index.jar";
receivedProgress = false; receivedProgress = false;
URL url = new URL(urlString); Uri uri = Uri.parse(urlString);
File destFile = File.createTempFile("dl-", ""); File destFile = File.createTempFile("dl-", "");
final HttpDownloader httpDownloader = new HttpDownloader(url, destFile); final HttpDownloader httpDownloader = new HttpDownloader(uri, destFile);
httpDownloader.setListener(new ProgressListener() { httpDownloader.setListener(new ProgressListener() {
@Override @Override
public void onProgress(URL sourceUrl, int bytesRead, int totalBytes) { public void onProgress(String urlString, long bytesRead, long totalBytes) {
receivedProgress = true; receivedProgress = true;
} }
}); });
@ -76,9 +76,9 @@ public class HttpDownloaderTest {
@Test @Test
public void downloadHttpBasicAuth() throws IOException, InterruptedException { public void downloadHttpBasicAuth() throws IOException, InterruptedException {
URL url = new URL("https://httpbin.org/basic-auth/myusername/supersecretpassword"); Uri uri = Uri.parse("https://httpbin.org/basic-auth/myusername/supersecretpassword");
File destFile = File.createTempFile("dl-", ""); File destFile = File.createTempFile("dl-", "");
HttpDownloader httpDownloader = new HttpDownloader(url, destFile, "myusername", "supersecretpassword"); HttpDownloader httpDownloader = new HttpDownloader(uri, destFile, "myusername", "supersecretpassword");
httpDownloader.download(); httpDownloader.download();
assertTrue(destFile.exists()); assertTrue(destFile.exists());
assertTrue(destFile.canRead()); assertTrue(destFile.canRead());
@ -87,9 +87,9 @@ public class HttpDownloaderTest {
@Test(expected = IOException.class) @Test(expected = IOException.class)
public void downloadHttpBasicAuthWrongPassword() throws IOException, InterruptedException { public void downloadHttpBasicAuthWrongPassword() throws IOException, InterruptedException {
URL url = new URL("https://httpbin.org/basic-auth/myusername/supersecretpassword"); Uri uri = Uri.parse("https://httpbin.org/basic-auth/myusername/supersecretpassword");
File destFile = File.createTempFile("dl-", ""); File destFile = File.createTempFile("dl-", "");
HttpDownloader httpDownloader = new HttpDownloader(url, destFile, "myusername", "wrongpassword"); HttpDownloader httpDownloader = new HttpDownloader(uri, destFile, "myusername", "wrongpassword");
httpDownloader.download(); httpDownloader.download();
assertFalse(destFile.exists()); assertFalse(destFile.exists());
destFile.deleteOnExit(); destFile.deleteOnExit();
@ -97,9 +97,9 @@ public class HttpDownloaderTest {
@Test(expected = IOException.class) @Test(expected = IOException.class)
public void downloadHttpBasicAuthWrongUsername() throws IOException, InterruptedException { public void downloadHttpBasicAuthWrongUsername() throws IOException, InterruptedException {
URL url = new URL("https://httpbin.org/basic-auth/myusername/supersecretpassword"); Uri uri = Uri.parse("https://httpbin.org/basic-auth/myusername/supersecretpassword");
File destFile = File.createTempFile("dl-", ""); File destFile = File.createTempFile("dl-", "");
HttpDownloader httpDownloader = new HttpDownloader(url, destFile, "wrongusername", "supersecretpassword"); HttpDownloader httpDownloader = new HttpDownloader(uri, destFile, "wrongusername", "supersecretpassword");
httpDownloader.download(); httpDownloader.download();
assertFalse(destFile.exists()); assertFalse(destFile.exists());
destFile.deleteOnExit(); destFile.deleteOnExit();
@ -108,12 +108,12 @@ public class HttpDownloaderTest {
@Test @Test
public void downloadThenCancel() throws IOException, InterruptedException { public void downloadThenCancel() throws IOException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(2); final CountDownLatch latch = new CountDownLatch(2);
URL url = new URL("https://f-droid.org/repo/index.jar"); Uri uri = Uri.parse("https://f-droid.org/repo/index.jar");
File destFile = File.createTempFile("dl-", ""); File destFile = File.createTempFile("dl-", "");
final HttpDownloader httpDownloader = new HttpDownloader(url, destFile); final HttpDownloader httpDownloader = new HttpDownloader(uri, destFile);
httpDownloader.setListener(new ProgressListener() { httpDownloader.setListener(new ProgressListener() {
@Override @Override
public void onProgress(URL sourceUrl, int bytesRead, int totalBytes) { public void onProgress(String urlString, long bytesRead, long totalBytes) {
receivedProgress = true; receivedProgress = true;
latch.countDown(); latch.countDown();
} }