@Test public void download_file() { Storage storage = new Storage(); FileHandle file = Mockito.mock(FileHandle.class); when(file.file()).thenReturn(Mockito.mock(File.class)); FileDownloadTask task = Mockito.mock(FileDownloadTask.class); when(storageReference.getFile(Mockito.any(File.class))).thenReturn(task); when(task.addOnFailureListener(Mockito.any(OnFailureListener.class))).thenReturn(task); when(task.addOnSuccessListener(Mockito.any(OnSuccessListener.class))).then(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { ((OnSuccessListener) invocation.getArgument(0)).onSuccess(Mockito.mock(FileDownloadTask.TaskSnapshot.class)); return null; } }); storage.download("test", file).silentFail().subscribe(); Mockito.verify(storageReference, VerificationModeFactory.times(1)).getFile(Mockito.any(File.class)); Mockito.verify(task, VerificationModeFactory.times(1)).addOnFailureListener(Mockito.any(OnFailureListener.class)); Mockito.verify(task, VerificationModeFactory.times(1)).addOnSuccessListener(Mockito.any(OnSuccessListener.class)); }
@Override public Promise<byte[]> download(final String path, final long bytesLimit) { return FuturePromise.when(new Consumer<FuturePromise<byte[]>>() { @Override public void accept(FuturePromise<byte[]> futurePromise) { downloadProcessor.processDownload(firebaseStorage(), path, bytesLimit, futurePromise); } }); }
Storage implements StorageDistribution { @Override public Promise<byte[]> download(final String path, final long bytesLimit) { return FuturePromise.when(new Consumer<FuturePromise<byte[]>>() { @Override public void accept(FuturePromise<byte[]> futurePromise) { downloadProcessor.processDownload(firebaseStorage(), path, bytesLimit, futurePromise); } }); } }
Storage implements StorageDistribution { @Override public Promise<byte[]> download(final String path, final long bytesLimit) { return FuturePromise.when(new Consumer<FuturePromise<byte[]>>() { @Override public void accept(FuturePromise<byte[]> futurePromise) { downloadProcessor.processDownload(firebaseStorage(), path, bytesLimit, futurePromise); } }); }  }
Storage implements StorageDistribution { @Override public Promise<byte[]> download(final String path, final long bytesLimit) { return FuturePromise.when(new Consumer<FuturePromise<byte[]>>() { @Override public void accept(FuturePromise<byte[]> futurePromise) { downloadProcessor.processDownload(firebaseStorage(), path, bytesLimit, futurePromise); } }); }  @Override Promise<FileMetadata> upload(final String path, final FileHandle file); @Override Promise<FileMetadata> upload(final String path, final byte[] data); @Override Promise<byte[]> download(final String path, final long bytesLimit); @Override Promise<FileHandle> download(final String path, final FileHandle targetFile); @Override Promise<Void> delete(final String path); @Override StorageDistribution inBucket(String url); }
Storage implements StorageDistribution { @Override public Promise<byte[]> download(final String path, final long bytesLimit) { return FuturePromise.when(new Consumer<FuturePromise<byte[]>>() { @Override public void accept(FuturePromise<byte[]> futurePromise) { downloadProcessor.processDownload(firebaseStorage(), path, bytesLimit, futurePromise); } }); }  @Override Promise<FileMetadata> upload(final String path, final FileHandle file); @Override Promise<FileMetadata> upload(final String path, final byte[] data); @Override Promise<byte[]> download(final String path, final long bytesLimit); @Override Promise<FileHandle> download(final String path, final FileHandle targetFile); @Override Promise<Void> delete(final String path); @Override StorageDistribution inBucket(String url);  }