Search in sources :

Example 6 with DownloadStatus

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

the class HttpDownloaderTest method testCancel.

public void testCancel() {
    final String url = HTTPBin.BASE_URL + "/delay/3";
    FeedFileImpl feedFile = setupFeedFile(url, "delay", true);
    final Downloader downloader = new HttpDownloader(new DownloadRequest(feedFile.getFile_url(), url, "delay", 0, feedFile.getTypeAsInt()));
    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) FeedFile(de.danoeh.antennapod.core.feed.FeedFile) File(java.io.File)

Aggregations

DownloadStatus (de.danoeh.antennapod.core.service.download.DownloadStatus)6 DownloadRequest (de.danoeh.antennapod.core.service.download.DownloadRequest)3 Downloader (de.danoeh.antennapod.core.service.download.Downloader)3 HttpDownloader (de.danoeh.antennapod.core.service.download.HttpDownloader)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Cursor (android.database.Cursor)2 LayoutInflater (android.view.LayoutInflater)2 FeedFile (de.danoeh.antennapod.core.feed.FeedFile)2 Dialog (android.app.Dialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Looper (android.os.Looper)1 NavUtils (android.support.v4.app.NavUtils)1 AlertDialog (android.support.v7.app.AlertDialog)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1