DriveStreamsManager implements GoogleApiClient.ConnectionCallbacks { @NonNull public synchronized Single<FileList> getFilesInFolder(@NonNull final String folderId) { Preconditions.checkNotNull(folderId); return newBlockUntilConnectedCompletable() .andThen(driveDataStreams.getFilesInFolder(folderId)) .doOnError(throwable -> driveErrorStream.onNext(Optional.of(syncErrorTranslator.get(throwable)))); } DriveStreamsManager(@NonNull Context context,
                               @NonNull DriveServiceHelper driveServiceHelper,
                               @NonNull GoogleDriveSyncMetadata googleDriveSyncMetadata,
                               @NonNull Subject<Optional<Throwable>> driveErrorStream); @VisibleForTesting  DriveStreamsManager(@NonNull DriveDataStreams driveDataStreams,
                        @NonNull DriveStreamMappings driveStreamMappings,
                        @NonNull Subject<Optional<Throwable>> driveErrorStream,
                        @NonNull DriveThrowableToSyncErrorTranslator syncErrorTranslator); @Override void onConnected(@Nullable Bundle bundle); @Override void onConnectionSuspended(int cause); @NonNull Single<List<RemoteBackupMetadata>> getRemoteBackups(); @NonNull synchronized Single<FileList> getAllFiles(); @NonNull synchronized Single<FileList> getFilesInFolder(@NonNull final String folderId); @NonNull synchronized Single<FileList> getFilesInFolder(@NonNull final String driveFolderId, @NonNull final String fileName); @NonNull Single<SyncState> uploadFileToDrive(@NonNull final SyncState currentSyncState, @NonNull final java.io.File file); @NonNull Single<Identifier> uploadFileToDrive(@NonNull final java.io.File file); @NonNull Single<SyncState> updateDriveFile(@NonNull final SyncState currentSyncState, @NonNull final java.io.File file); @NonNull Single<Identifier> updateDriveFile(@NonNull final Identifier currentIdentifier, @NonNull final java.io.File file); @NonNull Single<SyncState> deleteDriveFile(@NonNull final SyncState currentSyncState, final boolean isFullDelete); @NonNull Single<File> renameBackup(@NonNull final Identifier identifier, @NonNull final String newFileName); @NonNull Single<Boolean> delete(@NonNull final Identifier identifier); void clearCachedData(); @NonNull Single<Optional<java.io.File>> download(@NonNull final String fileId, @NonNull final java.io.File downloadLocationFile);  }
@Test public void getFilesInFolder() throws Exception { when(driveDataStreams.getFilesInFolder(anyString())).thenReturn(Single.just(fileList)); final TestObserver<FileList> testObserver = driveStreamsManager.getFilesInFolder(anyString()).test(); testObserver.assertValue(fileList); testObserver.assertComplete(); testObserver.assertNoErrors(); }
@Test public void getFilesInFolderErrorIsForwarded() throws Exception { final Exception exception = new Exception("test"); when(driveDataStreams.getFilesInFolder(anyString())).thenReturn(Single.error(exception)); final TestObserver<FileList> testObserver = driveStreamsManager.getFilesInFolder(anyString()).test(); testObserver.assertNoValues(); testObserver.assertNotComplete(); testObserver.assertError(Exception.class); verify(driveErrorStream).onNext(Optional.of(criticalSyncError)); }
@Test public void getFilesInFolderForName() throws Exception { final String filename = "filename"; final String folderId = "folderId"; when(driveDataStreams.getFilesInFolder(folderId, filename)).thenReturn(Single.just(fileList)); final TestObserver<FileList> testObserver = driveStreamsManager.getFilesInFolder(folderId, filename).test(); testObserver.assertValue(fileList); testObserver.assertComplete(); testObserver.assertNoErrors(); }
@Test public void getFilesInFolderErrorIsForwardedForName() throws Exception { final String filename = "filename"; final String folderId = "folderId"; final Exception exception = new Exception("test"); when(driveDataStreams.getFilesInFolder(folderId, filename)).thenReturn(Single.error(exception)); final TestObserver<FileList> testObserver = driveStreamsManager.getFilesInFolder(folderId, filename).test(); testObserver.assertNoValues(); testObserver.assertNotComplete(); testObserver.assertError(Exception.class); verify(driveErrorStream).onNext(Optional.of(criticalSyncError)); }