DeleteRepositoryPresenter { public void deleteRepository() { final CurrentProject project = appContext.getCurrentProject(); service.deleteRepository(project.getRootProject(), new AsyncRequestCallback<Void>() { @Override protected void onSuccess(Void result) { project.getRootProject().getAttributes().get("vcs.provider.name").clear(); console.printInfo(constant.deleteGitRepositorySuccess()); notificationManager.showInfo(constant.deleteGitRepositorySuccess()); projectExplorer.reloadChildren(); } @Override protected void onFailure(Throwable exception) { console.printError(exception.getMessage()); notificationManager.showError(exception.getMessage()); } }); } @Inject  DeleteRepositoryPresenter(GitServiceClient service,
                                     GitLocalizationConstant constant,
                                     GitOutputPartPresenter console,
                                     AppContext appContext,
                                     NotificationManager notificationManager,
                                     ProjectExplorerPresenter projectExplorer); void deleteRepository();  }
@Test public void testDeleteRepositoryWhenDeleteRepositoryIsSuccessful() throws Exception { Map attributes = mock(Map.class); List vcsProvider = mock(List.class); when(rootProjectDescriptor.getAttributes()).thenReturn(attributes); when(attributes.get("vcs.provider.name")).thenReturn(vcsProvider); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncRequestCallback<Void> callback = (AsyncRequestCallback<Void>)arguments[1]; Method onSuccess = GwtReflectionUtils.getMethod(callback.getClass(), "onSuccess"); onSuccess.invoke(callback, (Void)null); return callback; } }).when(service).deleteRepository((ProjectDescriptor)anyObject(), (AsyncRequestCallback<Void>)anyObject()); presenter.deleteRepository(); verify(appContext).getCurrentProject(); verify(service).deleteRepository(eq(rootProjectDescriptor), (AsyncRequestCallback<Void>)anyObject()); verify(console).printInfo(anyString()); verify(notificationManager).showInfo(eq(constant.deleteGitRepositorySuccess())); verify(rootProjectDescriptor).getAttributes(); verify(attributes).get(anyString()); verify(vcsProvider).clear(); }
@Test public void testDeleteRepositoryWhenDeleteRepositoryIsFailed() throws Exception { doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); AsyncRequestCallback<Void> callback = (AsyncRequestCallback<Void>)arguments[1]; Method onFailure = GwtReflectionUtils.getMethod(callback.getClass(), "onFailure"); onFailure.invoke(callback, mock(Throwable.class)); return callback; } }).when(service).deleteRepository((ProjectDescriptor)anyObject(), (AsyncRequestCallback<Void>)anyObject()); presenter.deleteRepository(); verify(appContext).getCurrentProject(); verify(service).deleteRepository(eq(rootProjectDescriptor), (AsyncRequestCallback<Void>)anyObject()); verify(console).printError(anyString()); verify(notificationManager).showError(anyString()); }