ReaderViewPresenter extends BasePresenter<ReaderView> implements TTSPlayerFragment.OnTTSStopSpeakListener { void openLink(String link) { openChapterFromLink(new BibleReference(link)); } @Inject  ReaderViewPresenter(Librarian librarian, PreferenceHelper prefHelper, AnalyticsHelper helper); @Override void onStopSpeak(); @Override void onViewCreated();  }
@Test public void openLinkFromUri() throws Exception { final String baseUrl = "/root/path"; final String humanLink = "Gen 1:1"; initMocks(baseUrl, humanLink); when(librarian.openChapter(any())).thenReturn(mock(Chapter.class)); presenter.openLink(Uri.parse("http: ArgumentCaptor<BibleReference> captorBR = ArgumentCaptor.forClass(BibleReference.class); verify(librarian).openChapter(captorBR.capture()); assertEquals("RST.Gen.1.1", captorBR.getValue().getPath()); verify(librarian).getCurrModule(); verify(view).setTextFormatter(any(ModuleTextFormatter.class)); verify(view).setContent(eq(baseUrl), any(Chapter.class), eq(1), eq(true)); verify(view).setTitle(eq("RST"), eq(humanLink)); InOrder progressOrder = inOrder(view); progressOrder.verify(view).showProgress(eq(false)); progressOrder.verify(view).hideProgress(); }
@Test public void openLinkStringWithClosedActivity() throws Exception { final String baseUrl = "/root/path"; final String humanLink = "Gen 1:1"; initMocks(baseUrl, humanLink); doAnswer(invocation -> { presenter.detachView(); return mock(Chapter.class); }).when(librarian).openChapter(any()); presenter.openLink("RST.Gen.1.1"); verify(view).showProgress(eq(false)); verify(view, never()).setTitle(anyString(), anyString()); verify(view, never()).onOpenChapterFailure(any()); }
@Test public void openLinkStringWithError() throws Exception { final String baseUrl = "/root/path"; final String humanLink = "Gen 1:1"; initMocks(baseUrl, humanLink); when(librarian.openChapter(any())).thenThrow(new OpenModuleException("RST", "")); presenter.openLink("RST.Gen.1.1"); InOrder progressOrder = inOrder(view); progressOrder.verify(view).showProgress(eq(false)); progressOrder.verify(view).onOpenChapterFailure(any(OpenModuleException.class)); }