OcrInformationalTooltipInteractor { @NonNull public Observable<OcrTooltipMessageType> getShowOcrTooltip() { return stateTracker.shouldShowOcrInfo() .subscribeOn(Schedulers.computation()) .flatMapObservable(shouldShowTooltip -> { if (shouldShowTooltip) { if (!configurationManager.isEnabled(ConfigurableResourceFeature.Ocr)) { Logger.info(OcrInformationalTooltipInteractor.this, "OCR is not configured. Disabling the tooltip"); return Observable.empty(); } if (ocrPurchaseTracker.getRemainingScans() > 0 && ocrPurchaseTracker.getRemainingScans() <= SCANS_LEFT_TO_INFORM) { return Observable.just(OcrTooltipMessageType.LimitedScansRemaining); } if (identityManager.isLoggedIn()) { if (ocrPurchaseTracker.hasAvailableScans()) { return Observable.empty(); } else { return Observable.just(OcrTooltipMessageType.NoScansRemaining); } } else { return Observable.just(OcrTooltipMessageType.NotConfigured); } } else { return Observable.empty(); } }) .doOnNext(ocrTooltipMessageType -> { Logger.info(OcrInformationalTooltipInteractor.this, "Displaying OCR Tooltip: {}", ocrTooltipMessageType); analytics.record(new DefaultDataPointEvent(Events.Ocr.OcrInfoTooltipShown).addDataPoint(new DataPoint("type", ocrTooltipMessageType))); }); } @Inject  OcrInformationalTooltipInteractor(@NonNull Analytics analytics,
                                             @NonNull OcrInformationalTooltipStateTracker stateTracker,
                                             @NonNull OcrPurchaseTracker ocrPurchaseTracker,
                                             @NonNull IdentityManager identityManager,
                                             @NonNull ConfigurationManager configurationManager); @VisibleForTesting  OcrInformationalTooltipInteractor(@NonNull Analytics analytics,
                                      @NonNull OcrInformationalTooltipStateTracker stateTracker,
                                      @NonNull OcrPurchaseTracker ocrPurchaseTracker,
                                      @NonNull IdentityManager identityManager,
                                      @NonNull ConfigurationManager configurationManager,
                                      @NonNull Scheduler scheduler); @SuppressLint("CheckResult") @SuppressWarnings("ResultOfMethodCallIgnored") void initialize(); @NonNull Observable<OcrTooltipMessageType> getShowOcrTooltip(); void markTooltipInteraction();  }
@Test public void getShowOcrTooltipWhenOcrIsNotEnabled() { when(stateTracker.shouldShowOcrInfo()).thenReturn(Single.just(true)); when(configurationManager.isEnabled(ConfigurableResourceFeature.Ocr)).thenReturn(false); TestObserver<OcrTooltipMessageType> testObserver = interactor.getShowOcrTooltip().test(); testObserver.awaitTerminalEvent(); testObserver.assertNoValues(); testObserver.assertComplete(); testObserver.assertNoErrors(); verify(stateTracker, never()).setShouldShowOcrInfo(anyBoolean()); }
@Test public void getShowOcrTooltipForLotsOfPurchasesWhenSetToShowTooltip() { when(stateTracker.shouldShowOcrInfo()).thenReturn(Single.just(true)); when(ocrPurchaseTracker.getRemainingScans()).thenReturn(OcrInformationalTooltipInteractor.SCANS_LEFT_TO_INFORM + 1); when(ocrPurchaseTracker.hasAvailableScans()).thenReturn(true); when(identityManager.isLoggedIn()).thenReturn(true); TestObserver<OcrTooltipMessageType> testObserver = interactor.getShowOcrTooltip().test(); testObserver.awaitTerminalEvent(); testObserver.assertNoValues(); testObserver.assertComplete(); testObserver.assertNoErrors(); verify(stateTracker, never()).setShouldShowOcrInfo(anyBoolean()); }
@Test public void getShowOcrTooltipForLimitedPurchasesWhenSetToShowTooltip() { when(stateTracker.shouldShowOcrInfo()).thenReturn(Single.just(true)); when(ocrPurchaseTracker.getRemainingScans()).thenReturn(OcrInformationalTooltipInteractor.SCANS_LEFT_TO_INFORM); when(identityManager.isLoggedIn()).thenReturn(true); TestObserver<OcrTooltipMessageType> testObserver = interactor.getShowOcrTooltip().test(); testObserver.awaitTerminalEvent(); testObserver.assertValue(OcrTooltipMessageType.LimitedScansRemaining); testObserver.assertComplete(); testObserver.assertNoErrors(); verify(stateTracker, never()).setShouldShowOcrInfo(anyBoolean()); }
@Test public void getShowOcrTooltipForLimitedPurchasesWhenNotSetToShowTooltip() { when(stateTracker.shouldShowOcrInfo()).thenReturn(Single.just(false)); when(ocrPurchaseTracker.getRemainingScans()).thenReturn(OcrInformationalTooltipInteractor.SCANS_LEFT_TO_INFORM); when(identityManager.isLoggedIn()).thenReturn(true); TestObserver<OcrTooltipMessageType> testObserver = interactor.getShowOcrTooltip().test(); testObserver.awaitTerminalEvent(); testObserver.assertNoValues(); testObserver.assertComplete(); testObserver.assertNoErrors(); verify(stateTracker, never()).setShouldShowOcrInfo(anyBoolean()); }
@Test public void getShowOcrTooltipForNotConfiguredWhenSetToShowTooltip() { when(stateTracker.shouldShowOcrInfo()).thenReturn(Single.just(true)); TestObserver<OcrTooltipMessageType> testObserver = interactor.getShowOcrTooltip().test(); testObserver.awaitTerminalEvent(); testObserver.assertValue(OcrTooltipMessageType.NotConfigured); testObserver.assertComplete(); testObserver.assertNoErrors(); verify(stateTracker, never()).setShouldShowOcrInfo(anyBoolean()); }
@Test public void getShowOcrTooltipForNotConfiguredWhenNotSetToShowTooltip() { when(stateTracker.shouldShowOcrInfo()).thenReturn(Single.just(false)); TestObserver<OcrTooltipMessageType> testObserver = interactor.getShowOcrTooltip().test(); testObserver.awaitTerminalEvent(); testObserver.assertNoValues(); testObserver.assertComplete(); testObserver.assertNoErrors(); verify(stateTracker, never()).setShouldShowOcrInfo(anyBoolean()); }
@Test public void getShowOcrTooltipForNoRemainingPurchasesWhenSetToShowTooltip() { when(stateTracker.shouldShowOcrInfo()).thenReturn(Single.just(true)); when(ocrPurchaseTracker.hasAvailableScans()).thenReturn(false); when(identityManager.isLoggedIn()).thenReturn(true); TestObserver<OcrTooltipMessageType> testObserver = interactor.getShowOcrTooltip().test(); testObserver.awaitTerminalEvent(); testObserver.assertValue(OcrTooltipMessageType.NoScansRemaining); testObserver.assertComplete(); testObserver.assertNoErrors(); verify(stateTracker, never()).setShouldShowOcrInfo(anyBoolean()); }
@Test public void getShowOcrTooltipForNoRemainingPurchasesWhenNotSetToShowTooltip() { when(stateTracker.shouldShowOcrInfo()).thenReturn(Single.just(false)); when(ocrPurchaseTracker.hasAvailableScans()).thenReturn(false); when(identityManager.isLoggedIn()).thenReturn(true); TestObserver<OcrTooltipMessageType> testObserver = interactor.getShowOcrTooltip().test(); testObserver.awaitTerminalEvent(); testObserver.assertNoValues(); testObserver.assertComplete(); testObserver.assertNoErrors(); verify(stateTracker, never()).setShouldShowOcrInfo(anyBoolean()); }