InitRepositoryPresenter { public void initRepository() { final CurrentProject currentProject = appContext.getCurrentProject(); if (currentProject == null || currentProject.getRootProject() == null) { Log.error(getClass(), "Open the project before initialize repository"); return; } gitRepositoryInitializer.initGitRepository(currentProject.getRootProject(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { handleError(caught); } @Override public void onSuccess(Void result) { console.printInfo(constant.initSuccess()); notificationManager.showInfo(constant.initSuccess()); projectExplorer.reloadChildren(); } }); } @Inject  InitRepositoryPresenter(AppContext appContext,
                                   GitLocalizationConstant constant,
                                   GitOutputPartPresenter console,
                                   NotificationManager notificationManager,
                                   GitRepositoryInitializer gitRepositoryInitializer,
                                   ProjectExplorerPresenter projectExplorer); void initRepository();  }
@Test public void testOnOkClickedInitWSRequestAndGetProjectIsSuccessful() throws Exception { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncCallback<Void> callback = (AsyncCallback<Void>)arguments[1]; Method onSuccess = GwtReflectionUtils.getMethod(callback.getClass(), "onSuccess"); onSuccess.invoke(callback, (Void)null); return callback; } }).when(gitRepositoryInitializer).initGitRepository((ProjectDescriptor)anyObject(), (AsyncCallback<Void>)anyObject()); presenter.initRepository(); verify(gitRepositoryInitializer).initGitRepository(eq(rootProjectDescriptor), (AsyncCallback<Void>)anyObject()); verify(console).printInfo(eq(constant.initSuccess())); verify(notificationManager).showInfo(eq(constant.initSuccess())); }
@Test public void testOnOkClickedInitWSRequestIsFailed() throws Exception { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncCallback<String> callback = (AsyncCallback<String>)arguments[1]; Method onFailure = GwtReflectionUtils.getMethod(callback.getClass(), "onFailure"); onFailure.invoke(callback, mock(Throwable.class)); return callback; } }).when(gitRepositoryInitializer).initGitRepository((ProjectDescriptor)anyObject(), (AsyncCallback<Void>)anyObject()); presenter.initRepository(); verify(gitRepositoryInitializer).initGitRepository(eq(rootProjectDescriptor), (AsyncCallback<Void>)anyObject()); verify(constant).initFailed(); verify(console).printError(eq(constant.initFailed())); verify(notificationManager).showError(eq(constant.initFailed())); }