ReportTooltipInteractor { public Observable<ReportTooltipUiIndicator> checkTooltipCauses() { return Observable.combineLatest( getErrorStream() .doOnNext(syncErrorType -> { analytics.record(new DefaultDataPointEvent(Events.Sync.DisplaySyncError) .addDataPoint(new DataPoint(SyncErrorType.class.getName(), syncErrorType))); Logger.info(this, "Received sync error: {}.", syncErrorType); }) .flatMap(syncErrorType -> Observable.just(ReportTooltipUiIndicator.syncError(syncErrorType))) .startWith(ReportTooltipUiIndicator.none()), getInfoStream(), (errorUiIndicator, infoUiIndicator) -> errorUiIndicator.getState() != None ? errorUiIndicator : infoUiIndicator) .observeOn(AndroidSchedulers.mainThread()); } @Inject  ReportTooltipInteractor(T activity, NavigationHandler navigationHandler,
                                   BackupProvidersManager backupProvidersManager,
                                   Analytics analytics, GenerateInfoTooltipManager infoTooltipManager,
                                   BackupReminderTooltipManager backupReminderTooltipManager,
                                   ImportInfoTooltipManager importInfoTooltipManager); Observable<ReportTooltipUiIndicator> checkTooltipCauses(); void handleClickOnErrorTooltip(@NonNull SyncErrorType syncErrorType); void generateInfoTooltipClosed(); void backupReminderTooltipClosed(); void importInfoTooltipClosed();  }
@Test public void getErrors() throws InterruptedException { when(backupProvidersManager.getCriticalSyncErrorStream()).thenReturn(Observable.just(new CriticalSyncError(new Throwable(), errorType))); interactor.checkTooltipCauses() .test() .assertNoErrors() .assertValue(ReportTooltipUiIndicator.syncError(errorType)); }
@Test public void getErrorsFirst() { when(backupProvidersManager.getCriticalSyncErrorStream()).thenReturn(Observable.just(new CriticalSyncError(new Throwable(), errorType))); when(generateInfoTooltipManager.needToShowGenerateTooltip()).thenReturn(Single.just(true)); when(backupReminderTooltipManager.needToShowBackupReminder()).thenReturn(Maybe.just(15)); when(importInfoTooltipManager.needToShowImportInfo()).thenReturn(Observable.just(true)); interactor.checkTooltipCauses() .test() .assertNoErrors() .assertValue(ReportTooltipUiIndicator.syncError(errorType)); }
@Test public void getGenerateInfoWhenErrorsArePossible() { when(backupProvidersManager.getCriticalSyncErrorStream()).thenReturn(Observable.never()); when(generateInfoTooltipManager.needToShowGenerateTooltip()).thenReturn(Single.just(true)); interactor.checkTooltipCauses() .test() .assertNoErrors() .assertValue(ReportTooltipUiIndicator.generateInfo()); }
@Test public void getGenerateInfoWhenErrorsAreImpossible() { when(backupProvidersManager.getCriticalSyncErrorStream()).thenReturn(Observable.empty()); when(generateInfoTooltipManager.needToShowGenerateTooltip()).thenReturn(Single.just(true)); interactor.checkTooltipCauses() .test() .assertNoErrors() .assertValue(ReportTooltipUiIndicator.generateInfo()); }
@Test public void getNoneWhenErrorsArePossible() { when(backupProvidersManager.getCriticalSyncErrorStream()).thenReturn(Observable.never()); interactor.checkTooltipCauses() .test() .assertNoErrors() .assertValue(ReportTooltipUiIndicator.none()); }
@Test public void getNoneWhenErrorsAreImpossible() { when(backupProvidersManager.getCriticalSyncErrorStream()).thenReturn(Observable.empty()); interactor.checkTooltipCauses() .test() .assertNoErrors() .assertValue(ReportTooltipUiIndicator.none()); }
@Test public void getBackupReminder() { when(backupReminderTooltipManager.needToShowBackupReminder()).thenReturn(Maybe.just(DAYS)); interactor.checkTooltipCauses() .test() .assertNoErrors() .assertValue(ReportTooltipUiIndicator.backupReminder(DAYS)); }
@Test public void getBackupReminderFirst() { when(generateInfoTooltipManager.needToShowGenerateTooltip()).thenReturn(Single.just(true)); when(backupReminderTooltipManager.needToShowBackupReminder()).thenReturn(Maybe.just(DAYS)); interactor.checkTooltipCauses() .test() .assertNoErrors() .assertValue(ReportTooltipUiIndicator.backupReminder(DAYS)); }
@Test public void getImportInfo() { when(importInfoTooltipManager.needToShowImportInfo()).thenReturn(Observable.just(true)); interactor.checkTooltipCauses() .test() .assertNoErrors() .assertValue(ReportTooltipUiIndicator.importInfo()); }
@Test public void getImportInfoFirst() { when(generateInfoTooltipManager.needToShowGenerateTooltip()).thenReturn(Single.just(true)); when(backupReminderTooltipManager.needToShowBackupReminder()).thenReturn(Maybe.just(DAYS)); when(importInfoTooltipManager.needToShowImportInfo()).thenReturn(Observable.just(true)); interactor.checkTooltipCauses() .test() .assertNoErrors() .assertValue(ReportTooltipUiIndicator.importInfo()); }