Search in sources :

Example 16 with DownloadBuilder

use of com.google.android.exoplayer2.testutil.DownloadBuilder in project ExoPlayer by google.

the class DefaultDownloadIndexTest method setSingleDownloadStopReason_setReason.

@Test
public void setSingleDownloadStopReason_setReason() throws Exception {
    String id = "id";
    DownloadBuilder downloadBuilder = new DownloadBuilder(id).setState(Download.STATE_FAILED).setFailureReason(FAILURE_REASON_UNKNOWN);
    Download download = downloadBuilder.build();
    downloadIndex.putDownload(download);
    int stopReason = 0x12345678;
    downloadIndex.setStopReason(id, stopReason);
    Download readDownload = downloadIndex.getDownload(id);
    Download expectedDownload = downloadBuilder.setStopReason(stopReason).build();
    assertEqual(readDownload, expectedDownload);
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) Test(org.junit.Test)

Example 17 with DownloadBuilder

use of com.google.android.exoplayer2.testutil.DownloadBuilder in project ExoPlayer by google.

the class DefaultDownloadIndexTest method downloadIndex_versionDowngradeWipesData.

@Test
public void downloadIndex_versionDowngradeWipesData() throws DatabaseIOException {
    Download download1 = new DownloadBuilder("id1").build();
    downloadIndex.putDownload(download1);
    DownloadCursor cursor = downloadIndex.getDownloads();
    assertThat(cursor.getCount()).isEqualTo(1);
    cursor.close();
    SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
    VersionTable.setVersion(writableDatabase, VersionTable.FEATURE_OFFLINE, EMPTY_NAME, Integer.MAX_VALUE);
    downloadIndex = new DefaultDownloadIndex(databaseProvider);
    cursor = downloadIndex.getDownloads();
    assertThat(cursor.getCount()).isEqualTo(0);
    cursor.close();
    assertThat(VersionTable.getVersion(writableDatabase, VersionTable.FEATURE_OFFLINE, EMPTY_NAME)).isEqualTo(DefaultDownloadIndex.TABLE_VERSION);
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Test(org.junit.Test)

Example 18 with DownloadBuilder

use of com.google.android.exoplayer2.testutil.DownloadBuilder in project ExoPlayer by google.

the class DefaultDownloadIndexTest method setSingleDownloadStopReason_setReasonToNone.

@Test
public void setSingleDownloadStopReason_setReasonToNone() throws Exception {
    String id = "id";
    DownloadBuilder downloadBuilder = new DownloadBuilder(id).setState(Download.STATE_COMPLETED).setStopReason(0x12345678);
    Download download = downloadBuilder.build();
    downloadIndex.putDownload(download);
    downloadIndex.setStopReason(id, STOP_REASON_NONE);
    Download readDownload = downloadIndex.getDownload(id);
    Download expectedDownload = downloadBuilder.setStopReason(STOP_REASON_NONE).build();
    assertEqual(readDownload, expectedDownload);
}
Also used : DownloadBuilder(com.google.android.exoplayer2.testutil.DownloadBuilder) Test(org.junit.Test)

Aggregations

DownloadBuilder (com.google.android.exoplayer2.testutil.DownloadBuilder)18 Test (org.junit.Test)18 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2