IntentImportInformationPresenter extends BaseViperPresenter<IntentImportInformationView, IntentImportInformationInteractor> { @Override public void subscribe() { compositeDisposable.add(intentImportProvider.getIntentMaybe() .flatMapObservable(interactor::process) .observeOn(AndroidSchedulers.mainThread()) .filter(uiIndicator -> uiIndicator.getState() == UiIndicator.State.Success) .subscribe(uiIndicator -> { final IntentImportResult result = uiIndicator.getData().get(); if (result.getFileType() == FileType.Smr) { navigationHandler.showDialog(ImportLocalBackupDialogFragment.newInstance(result.getUri())); } else { view.presentIntentImportInformation(result.getFileType()); } }, throwable -> { Logger.error(IntentImportInformationPresenter.this, "Failed to process file import", throwable); view.presentIntentImportFatalError(); })); } @Inject  IntentImportInformationPresenter(@NonNull IntentImportInformationView view, @NonNull IntentImportInformationInteractor interactor,
                                            @NonNull IntentImportProvider intentImportProvider,
                                            @NonNull NavigationHandler<SmartReceiptsActivity> navigationHandler); @Override void subscribe();  }
@Test public void idleIndicatorsAreNotConsumed() { when(interactor.process(intent)).thenReturn(Observable.just(UiIndicator.idle(), UiIndicator.idle())); presenter.subscribe(); verifyZeroInteractions(view); verifyZeroInteractions(navigationHandler); }
@Test public void importSmrFileTriggersDialog() { when(interactor.process(intent)).thenReturn(Observable.just(UiIndicator.idle(), UiIndicator.success(new IntentImportResult(Uri.EMPTY, FileType.Smr)))); presenter.subscribe(); verify(navigationHandler).showDialog(any(ImportLocalBackupDialogFragment.class)); verifyZeroInteractions(view); }
@Test public void importImageTheFirstTimeShowsView() { when(interactor.process(intent)).thenReturn(Observable.just(UiIndicator.idle(), UiIndicator.success(new IntentImportResult(Uri.EMPTY, FileType.Image)))); presenter.subscribe(); verify(view).presentIntentImportInformation(FileType.Image); verifyNoMoreInteractions(view); verifyZeroInteractions(navigationHandler); }
@Test public void importPdfSubsequentlyShowsGenericView() { when(interactor.process(intent)).thenReturn(Observable.just(UiIndicator.idle(), UiIndicator.success(new IntentImportResult(Uri.EMPTY, FileType.Pdf)))); presenter.subscribe(); verify(view).presentIntentImportInformation(FileType.Pdf); verifyNoMoreInteractions(view); verifyZeroInteractions(navigationHandler); }
@Test public void errorsDisplayFatalView() { when(interactor.process(intent)).thenReturn(Observable.error(new Exception("test"))); presenter.subscribe(); verify(view).presentIntentImportFatalError(); verifyNoMoreInteractions(view); verifyZeroInteractions(navigationHandler); }