@Test public void upload() { Storage storage = new Storage(); FileHandle fileHandle = Mockito.mock(FileHandle.class); File file = Mockito.mock(File.class); when(fileHandle.file()).thenReturn(file); final UploadTask uploadTask = Mockito.mock(UploadTask.class); final Task task = Mockito.mock(Task.class); final UploadTask.TaskSnapshot taskSnapshot = Mockito.mock(UploadTask.TaskSnapshot.class); StorageMetadata storageMetadata = Mockito.mock(StorageMetadata.class); when(taskSnapshot.getMetadata()).thenReturn(storageMetadata); when(storageMetadata.getPath()).thenReturn("test"); when(storageReference.putFile(Mockito.any(Uri.class))).thenReturn(uploadTask); when(storageReference.getDownloadUrl()).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(Uri.class)); return null; } }); when(uploadTask.addOnFailureListener(Mockito.any(OnFailureListener.class))).thenReturn(uploadTask); when(uploadTask.addOnSuccessListener(Mockito.any(OnSuccessListener.class))).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) { ((OnSuccessListener) invocation.getArgument(0)).onSuccess(taskSnapshot); return uploadTask; } }); storage.upload("test", fileHandle).subscribe(); Mockito.verify(storageReference, VerificationModeFactory.times(1)).putFile(Mockito.any(Uri.class)); Mockito.verify(uploadTask, VerificationModeFactory.times(1)).addOnFailureListener(Mockito.any(OnFailureListener.class)); Mockito.verify(uploadTask, VerificationModeFactory.times(1)).addOnSuccessListener(Mockito.any(OnSuccessListener.class)); }
@Override public Promise<FileMetadata> upload(final String path, final FileHandle file) { return FuturePromise.when(new Consumer<FuturePromise<FileMetadata>>() { @Override public void accept(FuturePromise<FileMetadata> promise) { uploadProcessor.processUpload(firebaseStorage(), path, file, promise); } }); }
Storage implements StorageDistribution { @Override public Promise<FileMetadata> upload(final String path, final FileHandle file) { return FuturePromise.when(new Consumer<FuturePromise<FileMetadata>>() { @Override public void accept(FuturePromise<FileMetadata> promise) { uploadProcessor.processUpload(firebaseStorage(), path, file, promise); } }); } }
Storage implements StorageDistribution { @Override public Promise<FileMetadata> upload(final String path, final FileHandle file) { return FuturePromise.when(new Consumer<FuturePromise<FileMetadata>>() { @Override public void accept(FuturePromise<FileMetadata> promise) { uploadProcessor.processUpload(firebaseStorage(), path, file, promise); } }); }  }
Storage implements StorageDistribution { @Override public Promise<FileMetadata> upload(final String path, final FileHandle file) { return FuturePromise.when(new Consumer<FuturePromise<FileMetadata>>() { @Override public void accept(FuturePromise<FileMetadata> promise) { uploadProcessor.processUpload(firebaseStorage(), path, file, promise); } }); }  @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<FileMetadata> upload(final String path, final FileHandle file) { return FuturePromise.when(new Consumer<FuturePromise<FileMetadata>>() { @Override public void accept(FuturePromise<FileMetadata> promise) { uploadProcessor.processUpload(firebaseStorage(), path, file, promise); } }); }  @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);  }