Search in sources :

Example 1 with StorageDownloadFileOptions

use of com.amplifyframework.storage.options.StorageDownloadFileOptions in project amplify-android by aws-amplify.

the class RxStorageBindingTest method downloadFileReturnsResult.

/**
 * When {@link StorageCategoryBehavior#downloadFile(String, File, StorageDownloadFileOptions,
 * Consumer, Consumer, Consumer)} invokes its success callback, the {@link StorageDownloadFileResult}
 * should propagate via the {@link Single} returned by
 * {@link RxStorageBinding.RxProgressAwareSingleOperation#observeResult()}.
 * @throws InterruptedException not expected.
 */
@Test
public void downloadFileReturnsResult() throws InterruptedException {
    StorageDownloadFileResult result = StorageDownloadFileResult.fromFile(mock(File.class));
    doAnswer(invocation -> {
        // 0 key, 1 local, 2 options, 3 onProgress 4 onResult, 5 onError
        final int indexOfProgressConsumer = 3;
        final int indexOfResultConsumer = 4;
        Consumer<StorageTransferProgress> progressConsumer = invocation.getArgument(indexOfProgressConsumer);
        Consumer<StorageDownloadFileResult> resultConsumer = invocation.getArgument(indexOfResultConsumer);
        Observable.interval(100, 100, TimeUnit.MILLISECONDS).take(5).doOnNext(aLong -> progressConsumer.accept(new StorageTransferProgress(aLong, 500))).doOnComplete(() -> resultConsumer.accept(result)).subscribe();
        return mock(StorageDownloadFileOperation.class);
    }).when(delegate).downloadFile(eq(remoteKey), eq(localFile), any(StorageDownloadFileOptions.class), anyConsumer(), anyConsumer(), anyConsumer());
    RxStorageBinding.RxProgressAwareSingleOperation<StorageDownloadFileResult> rxOperation = rxStorage.downloadFile(remoteKey, localFile, StorageDownloadFileOptions.defaultInstance());
    TestObserver<StorageDownloadFileResult> testObserver = rxOperation.observeResult().test();
    TestObserver<StorageTransferProgress> testProgressObserver = rxOperation.observeProgress().test();
    testObserver.await(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    testObserver.assertValues(result);
    testProgressObserver.awaitCount(5);
    testProgressObserver.assertValueCount(5);
}
Also used : StorageDownloadFileResult(com.amplifyframework.storage.result.StorageDownloadFileResult) StorageDownloadFileOptions(com.amplifyframework.storage.options.StorageDownloadFileOptions) File(java.io.File) StorageTransferProgress(com.amplifyframework.storage.result.StorageTransferProgress) Test(org.junit.Test)

Aggregations

StorageDownloadFileOptions (com.amplifyframework.storage.options.StorageDownloadFileOptions)1 StorageDownloadFileResult (com.amplifyframework.storage.result.StorageDownloadFileResult)1 StorageTransferProgress (com.amplifyframework.storage.result.StorageTransferProgress)1 File (java.io.File)1 Test (org.junit.Test)1