Search in sources :

Example 11 with Downloader

use of de.danoeh.antennapod.core.service.download.Downloader in project AntennaPod by AntennaPod.

the class HttpDownloaderTest method testCancel.

@Test
public void testCancel() {
    final String url = httpServer.getBaseUrl() + "/delay/3";
    FeedFileImpl feedFile = setupFeedFile(url, "delay", true);
    final Downloader downloader = new HttpDownloader(new DownloadRequest(feedFile.getFile_url(), url, "delay", 0, feedFile.getTypeAsInt(), null, null, true, null, false));
    Thread t = new Thread() {

        @Override
        public void run() {
            downloader.call();
        }
    };
    t.start();
    downloader.cancel();
    try {
        t.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    DownloadStatus result = downloader.getResult();
    assertTrue(result.isDone());
    assertFalse(result.isSuccessful());
    assertTrue(result.isCancelled());
    assertFalse(new File(feedFile.getFile_url()).exists());
}
Also used : HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) DownloadStatus(de.danoeh.antennapod.core.service.download.DownloadStatus) Downloader(de.danoeh.antennapod.core.service.download.Downloader) HttpDownloader(de.danoeh.antennapod.core.service.download.HttpDownloader) DownloadRequest(de.danoeh.antennapod.core.service.download.DownloadRequest) File(java.io.File) FeedFile(de.danoeh.antennapod.model.feed.FeedFile) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Aggregations

Downloader (de.danoeh.antennapod.core.service.download.Downloader)11 HttpDownloader (de.danoeh.antennapod.core.service.download.HttpDownloader)6 DownloadRequest (de.danoeh.antennapod.core.service.download.DownloadRequest)5 DownloadStatus (de.danoeh.antennapod.core.service.download.DownloadStatus)5 LargeTest (androidx.test.filters.LargeTest)4 File (java.io.File)4 FeedFile (de.danoeh.antennapod.model.feed.FeedFile)3 Test (org.junit.Test)3 Dialog (android.app.Dialog)2 Context (android.content.Context)2 Bundle (android.os.Bundle)2 Log (android.util.Log)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 Snackbar (com.google.android.material.snackbar.Snackbar)2 R (de.danoeh.antennapod.R)2