GithubImporterPagePresenter extends AbstractWizardPage<ImportProject> implements GithubImporterPageView.ActionDelegate { @Override public void onLoadRepoClicked() { getUserRepos(); } @Inject  GithubImporterPagePresenter(GithubImporterPageView view,
                                       GitHubAuthenticator gitHubAuthenticator,
                                       NotificationManager notificationManager,
                                       GitHubClientService gitHubClientService,
                                       DtoFactory dtoFactory,
                                       GitHubLocalizationConstant locale); @Override boolean isCompleted(); @Override void projectNameChanged(@NotNull String name); @Override void projectUrlChanged(@NotNull String url); @Override void recursiveSelected(boolean recursiveSelected); @Override void projectDescriptionChanged(@NotNull String projectDescription); @Override void projectVisibilityChanged(boolean visible); @Override void keepDirectorySelected(boolean keepDirectory); @Override void keepDirectoryNameChanged(@NotNull String directoryName); @Override void go(@NotNull AcceptsOneWidget container); @Override void onLoadRepoClicked(); @Override void onRepositorySelected(@NotNull ProjectData repository); @Override void onAccountChanged();  }
@Test public void onLoadRepoClickedWhenGetUserReposIsSuccessful() throws Exception { final Map<String, List<GitHubRepository>> repositories = new HashMap<>(); List<GitHubRepository> repo = new ArrayList<>(); repositories.put("AccountName", repo); when(view.getAccountName()).thenReturn("AccountName"); presenter.onLoadRepoClicked(); verify(gitHubClientService).getAllRepositories(asyncRequestCallbackRepoListCaptor.capture()); AsyncRequestCallback<Map<String, List<GitHubRepository>>> asyncRequestCallback = asyncRequestCallbackRepoListCaptor.getValue(); GwtReflectionUtils.callOnSuccess(asyncRequestCallback, repositories); verify(notificationManager, never()).showError(anyString()); verify(view).setLoaderVisibility(eq(true)); verify(view).setInputsEnableState(eq(false)); verify(view).setLoaderVisibility(eq(false)); verify(view).setInputsEnableState(eq(true)); verify(gitHubClientService).getAllRepositories(Matchers.<AsyncRequestCallback<Map<String, List<GitHubRepository>>>>anyObject()); verify(view).setAccountNames(Matchers.<Set>anyObject()); verify(view, times(2)).showGithubPanel(); verify(view).setRepositories(Matchers.<List<ProjectData>>anyObject()); verify(view).reset(); }
@Test public void onLoadRepoClickedWhenGetUserReposIsFailed() throws Exception { final Throwable exception = mock(Throwable.class); when(exception.getMessage()).thenReturn(""); presenter.onLoadRepoClicked(); verify(gitHubClientService).getAllRepositories(asyncRequestCallbackRepoListCaptor.capture()); AsyncRequestCallback<Map<String, List<GitHubRepository>>> asyncRequestCallback = asyncRequestCallbackRepoListCaptor.getValue(); GwtReflectionUtils.callOnFailure(asyncRequestCallback, exception); verify(notificationManager).showError(anyString()); verify(view).setLoaderVisibility(eq(true)); verify(view).setInputsEnableState(eq(false)); verify(view).setLoaderVisibility(eq(false)); verify(view).setInputsEnableState(eq(true)); verify(gitHubClientService).getAllRepositories(Matchers.<AsyncRequestCallback<Map<String, List<GitHubRepository>>>>anyObject()); verify(view, never()).setAccountNames((Set<String>)anyObject()); verify(view, never()).showGithubPanel(); verify(view, never()).setRepositories(Matchers.<List<ProjectData>>anyObject()); }