AnalysisScreenPresenter extends AnalysisScreenContract.Presenter { @Override public void start() { mStopped = false; createDocumentRenderer(); clearParcelableMemoryCache(); getView().showScanAnimation(); loadDocumentData(); showHintsForImage(); } AnalysisScreenPresenter(
            @NonNull final Activity activity,
            @NonNull final AnalysisScreenContract.View view,
            @NonNull final Document document,
            @Nullable final String documentAnalysisErrorMessage); @VisibleForTesting  AnalysisScreenPresenter(
            @NonNull final Activity activity,
            @NonNull final AnalysisScreenContract.View view,
            @NonNull final Document document,
            @Nullable final String documentAnalysisErrorMessage,
            @NonNull final AnalysisInteractor analysisInteractor); @Override void hideError(); @Override void onNoExtractionsFound(); @Override void onDocumentAnalyzed(); @Override void showError(@NonNull final String message, final int duration); @Override void showError(@NonNull final String message, @NonNull final String buttonTitle,
            @NonNull final View.OnClickListener onClickListener); @Override void startScanAnimation(); @Override void stopScanAnimation(); @Override void setListener(@NonNull final AnalysisFragmentListener listener); @Override void start(); @Override void stop();  }
@Test public void should_startScanAnimation_whenStarted() throws Exception { final AnalysisScreenPresenter presenter = createPresenterWithEmptyImageDocument(); presenter.start(); verify(mView, atLeastOnce()).showScanAnimation(); }
@Test public void should_loadDocumentData_whenStarted() throws Exception { final GiniVisionDocument document = spy(DocumentFactory.newEmptyImageDocument( Document.Source.newCameraSource(), Document.ImportMethod.NONE)); final AnalysisScreenPresenter presenter = createPresenter(document); presenter.start(); verify(document).loadData(eq(mActivity), any(AsyncCallback.class)); }
@Test public void should_showDocument_afterDocumentWasLoaded() throws Exception { final ImageDocument imageDocument = new ImageDocumentFake(); when(mView.getPdfPreviewSize()).thenReturn(new Size(1024, 768)); final Bitmap bitmap = mock(Bitmap.class); final int rotationForDisplay = 90; final AnalysisScreenPresenter presenter = spy( createPresenter(imageDocument, bitmap, rotationForDisplay)); presenter.start(); verify(mView).showBitmap(bitmap, rotationForDisplay); }
@Test public void should_showError_ifAvailable_beforeAnalysis() throws Exception { final ImageDocument imageDocument = new ImageDocumentFake(); final String errorMessage = "Something went wrong"; final AnalysisScreenPresenter presenter = spy( createPresenter(imageDocument, errorMessage)); presenter.start(); verify(mView).showErrorSnackbar(eq(errorMessage), anyInt(), (String) any(), any(View.OnClickListener.class)); }
@Test public void should_startScanAnimation_whenAnalyzingDocument() throws Exception { final ImageDocument imageDocument = new ImageDocumentFake(); final AnalysisScreenPresenter presenter = createPresenter(imageDocument); presenter.start(); verify(mView, atLeast(2)).showScanAnimation(); }
@Test public void should_stopScanAnimation_whenAnalysisFinished() throws Exception { when(mActivity.getString(anyInt())).thenReturn("A String"); final ImageDocument imageDocument = new ImageDocumentFake(); final CompletableFuture<AnalysisInteractor.ResultHolder> analysisFuture = new CompletableFuture<>(); analysisFuture.complete(new AnalysisInteractor.ResultHolder( AnalysisInteractor.Result.SUCCESS_NO_EXTRACTIONS)); final AnalysisScreenPresenter presenter = createPresenterWithAnalysisFuture(imageDocument, analysisFuture); presenter.start(); verify(mView).hideScanAnimation(); }
@Test public void should_showError_whenAnalysisFailed() throws Exception { when(mActivity.getString(anyInt())).thenReturn("A String"); final ImageDocument imageDocument = new ImageDocumentFake(); final CompletableFuture<AnalysisInteractor.ResultHolder> analysisFuture = new CompletableFuture<>(); analysisFuture.completeExceptionally(new RuntimeException()); final AnalysisScreenPresenter presenter = createPresenterWithAnalysisFuture(imageDocument, analysisFuture); presenter.start(); verify(mView).showErrorSnackbar(anyString(), anyInt(), anyString(), any(View.OnClickListener.class)); }
@Test public void should_triggerErrorEvent_forError_fromReviewScreen() throws Exception { final EventTracker eventTracker = spy(EventTracker.class); new GiniVision.Builder().setEventTracker(eventTracker).build(); final ImageDocument imageDocument = new ImageDocumentFake(); final String errorMessage = "Something went wrong"; final AnalysisScreenPresenter presenter = createPresenter(imageDocument, errorMessage); presenter.start(); verify(eventTracker).onAnalysisScreenEvent(new Event<>(AnalysisScreenEvent.ERROR, Collections.singletonMap(AnalysisScreenEvent.ERROR_DETAILS_MAP_KEY.MESSAGE, errorMessage))); }
@Test public void should_triggerErrorEvent_forAnalysisError() throws Exception { final EventTracker eventTracker = spy(EventTracker.class); new GiniVision.Builder().setEventTracker(eventTracker).build(); final ImageDocument imageDocument = new ImageDocumentFake(); final CompletableFuture<AnalysisInteractor.ResultHolder> analysisFuture = new CompletableFuture<>(); analysisFuture.completeExceptionally(new RuntimeException("error message")); final AnalysisScreenPresenter presenter = createPresenterWithAnalysisFuture(imageDocument, analysisFuture); presenter.start(); verify(eventTracker).onAnalysisScreenEvent(new Event<>(AnalysisScreenEvent.ERROR, Collections.singletonMap(AnalysisScreenEvent.ERROR_DETAILS_MAP_KEY.MESSAGE, "error message"))); }
@Test public void should_triggerRetryEvent_forError_fromReviewScreen_whenRetry_wasClicked() throws Exception { final EventTracker eventTracker = spy(EventTracker.class); new GiniVision.Builder().setEventTracker(eventTracker).build(); final ImageDocument imageDocument = new ImageDocumentFake(); final String errorMessage = "Something went wrong"; final AnalysisScreenPresenter presenter = createPresenter(imageDocument, errorMessage); presenter.start(); final ArgumentCaptor<View.OnClickListener> onClickListenerCaptor = ArgumentCaptor.forClass( View.OnClickListener.class); verify(mView).showErrorSnackbar(anyString(), anyInt(), (String) any(), onClickListenerCaptor.capture()); onClickListenerCaptor.getValue().onClick(mock(View.class)); verify(eventTracker).onAnalysisScreenEvent(new Event<>(AnalysisScreenEvent.RETRY)); }
@Test public void should_triggerRetryEvent_forAnalysisError_whenRetry_wasClicked() throws Exception { when(mActivity.getString(anyInt())).thenReturn("A String"); final EventTracker eventTracker = spy(EventTracker.class); new GiniVision.Builder().setEventTracker(eventTracker).build(); final ImageDocument imageDocument = new ImageDocumentFake(); final CompletableFuture<AnalysisInteractor.ResultHolder> analysisFuture = new CompletableFuture<>(); analysisFuture.completeExceptionally(new RuntimeException("error message")); final AnalysisScreenPresenter presenter = createPresenterWithAnalysisFuture(imageDocument, analysisFuture); presenter.start(); final ArgumentCaptor<View.OnClickListener> onClickListenerCaptor = ArgumentCaptor.forClass( View.OnClickListener.class); verify(mView).showErrorSnackbar(anyString(), anyInt(), (String) any(), onClickListenerCaptor.capture()); onClickListenerCaptor.getValue().onClick(mock(View.class)); verify(eventTracker).onAnalysisScreenEvent(new Event<>(AnalysisScreenEvent.RETRY)); }