Java Code Examples for com.google.firebase.storage.FileDownloadTask#TaskSnapshot

The following examples show how to use com.google.firebase.storage.FileDownloadTask#TaskSnapshot . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RxFirebaseStorageTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void getFile() {

    TestSubscriber<FileDownloadTask.TaskSnapshot> testSubscriber = new TestSubscriber<>();
    RxFirebaseStorage.getFile(mockStorageRef, file)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(fileSnapshot);

    verify(mockStorageRef).getFile(file);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(fileSnapshot));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example 2
Source File: RxFirebaseStorageTests.java    From RxFirebase with Apache License 2.0 6 votes vote down vote up
@Test
public void getFileUri() {

    TestSubscriber<FileDownloadTask.TaskSnapshot> testSubscriber = new TestSubscriber<>();
    RxFirebaseStorage.getFile(mockStorageRef, uri)
            .subscribeOn(Schedulers.immediate())
            .subscribe(testSubscriber);

    testOnSuccessListener.getValue().onSuccess(fileSnapshot);

    verify(mockStorageRef).getFile(uri);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);
    testSubscriber.assertReceivedOnNext(Collections.singletonList(fileSnapshot));
    testSubscriber.assertNotCompleted();
    testSubscriber.unsubscribe();
}
 
Example 3
Source File: RxFirebaseStorageTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("Duplicates") @Test public void testGetFileUri() {
  mockSuccessfulResultForTask(mockFileDownloadTask, mockFileDownloadTaskSnapshot);
  when(mockStorageReference.getFile(mockUri)).thenReturn(mockFileDownloadTask);
  when(mockFileDownloadTaskSnapshot.getBytesTransferred()).thenReturn(1000L);
  when(mockFileDownloadTaskSnapshot.getTotalByteCount()).thenReturn(1000L);

  TestObserver<FileDownloadTask.TaskSnapshot> obs = TestObserver.create();

  RxFirebaseStorage.getFile(mockStorageReference, mockUri).subscribe(obs);

  verifyAddOnCompleteListenerForTask(mockFileDownloadTask);

  callOnComplete(mockFileDownloadTask);
  obs.dispose();

  callOnComplete(mockFileDownloadTask);

  obs.assertNoErrors();
  obs.assertComplete();
  obs.assertValue(new Predicate<FileDownloadTask.TaskSnapshot>() {
    @Override public boolean test(FileDownloadTask.TaskSnapshot taskSnapshot) throws Exception {
      return taskSnapshot.getBytesTransferred() == taskSnapshot.getTotalByteCount()
          && taskSnapshot.getTotalByteCount() == 1000;
    }
  });
}
 
Example 4
Source File: RxFirebaseStorageTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("Duplicates") @Test public void testGetFileUri_notSuccessful() {
  mockNotSuccessfulResultForTask(mockFileDownloadTask, new IllegalStateException());
  when(mockStorageReference.getFile(mockUri)).thenReturn(mockFileDownloadTask);

  TestObserver<FileDownloadTask.TaskSnapshot> obs = TestObserver.create();

  RxFirebaseStorage.getFile(mockStorageReference, mockUri).subscribe(obs);
  verifyAddOnCompleteListenerForTask(mockFileDownloadTask);

  callOnComplete(mockFileDownloadTask);
  obs.dispose();

  callOnComplete(mockFileDownloadTask);

  obs.assertError(IllegalStateException.class);
  obs.assertNoValues();
}
 
Example 5
Source File: RxFirebaseStorageTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("Duplicates") @Test public void testGetFile() {
  mockSuccessfulResultForTask(mockFileDownloadTask, mockFileDownloadTaskSnapshot);
  when(mockStorageReference.getFile(mockFile)).thenReturn(mockFileDownloadTask);
  when(mockFileDownloadTaskSnapshot.getBytesTransferred()).thenReturn(1000L);
  when(mockFileDownloadTaskSnapshot.getTotalByteCount()).thenReturn(1000L);

  TestObserver<FileDownloadTask.TaskSnapshot> obs = TestObserver.create();

  RxFirebaseStorage.getFile(mockStorageReference, mockFile).subscribe(obs);

  verifyAddOnCompleteListenerForTask(mockFileDownloadTask);

  callOnComplete(mockFileDownloadTask);
  obs.dispose();

  callOnComplete(mockFileDownloadTask);

  obs.assertNoErrors();
  obs.assertComplete();
  obs.assertValue(new Predicate<FileDownloadTask.TaskSnapshot>() {
    @Override public boolean test(FileDownloadTask.TaskSnapshot taskSnapshot) throws Exception {
      return taskSnapshot.getBytesTransferred() == taskSnapshot.getTotalByteCount()
          && taskSnapshot.getTotalByteCount() == 1000;
    }
  });
}
 
Example 6
Source File: RxFirebaseStorageTest.java    From rxfirebase with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("Duplicates") @Test public void testGetFile_notSuccessful() {
  mockNotSuccessfulResultForTask(mockFileDownloadTask, new IllegalStateException());
  when(mockStorageReference.getFile(mockFile)).thenReturn(mockFileDownloadTask);

  TestObserver<FileDownloadTask.TaskSnapshot> obs = TestObserver.create();

  RxFirebaseStorage.getFile(mockStorageReference, mockFile).subscribe(obs);
  verifyAddOnCompleteListenerForTask(mockFileDownloadTask);

  callOnComplete(mockFileDownloadTask);
  obs.dispose();

  callOnComplete(mockFileDownloadTask);

  obs.assertError(IllegalStateException.class);
  obs.assertNoValues();
}
 
Example 7
Source File: RxFirebaseStorage.java    From RxFirebase with Apache License 2.0 5 votes vote down vote up
@NonNull
public static Observable<FileDownloadTask.TaskSnapshot> getFile(@NonNull final StorageReference storageRef,
                                                                @NonNull final File destinationFile) {
    return Observable.unsafeCreate(new Observable.OnSubscribe<FileDownloadTask.TaskSnapshot>() {
        @Override
        public void call(final Subscriber<? super FileDownloadTask.TaskSnapshot> subscriber) {
            RxTask.assignOnTask(subscriber, storageRef.getFile(destinationFile));
        }
    });
}
 
Example 8
Source File: RxFirebaseStorage.java    From RxFirebase with Apache License 2.0 5 votes vote down vote up
@NonNull
public static Observable<FileDownloadTask.TaskSnapshot> getFile(@NonNull final StorageReference storageRef,
                                                                @NonNull final Uri destinationUri) {
    return Observable.unsafeCreate(new Observable.OnSubscribe<FileDownloadTask.TaskSnapshot>() {
        @Override
        public void call(final Subscriber<? super FileDownloadTask.TaskSnapshot> subscriber) {
            RxTask.assignOnTask(subscriber, storageRef.getFile(destinationUri));
        }
    });
}
 
Example 9
Source File: RxFirebaseStorage.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @see StorageReference#getFile(Uri)
 */
@CheckReturnValue
@NonNull
public static Single<FileDownloadTask.TaskSnapshot> getFile(@NonNull final StorageReference ref,
                                                            @NonNull final Uri uri) {
    return RxTask.single(new Callable<Task<FileDownloadTask.TaskSnapshot>>() {
        @Override
        public Task<FileDownloadTask.TaskSnapshot> call() throws Exception {
            return ref.getFile(uri);
        }
    });
}
 
Example 10
Source File: RxFirebaseStorage.java    From rxfirebase with Apache License 2.0 5 votes vote down vote up
/**
 * @see StorageReference#getFile(File)
 */
@CheckReturnValue
@NonNull
public static Single<FileDownloadTask.TaskSnapshot> getFile(@NonNull final StorageReference ref,
                                                            @NonNull final File file) {
    return RxTask.single(new Callable<Task<FileDownloadTask.TaskSnapshot>>() {
        @Override
        public Task<FileDownloadTask.TaskSnapshot> call() throws Exception {
            return ref.getFile(file);
        }
    });
}