@Test public void setupUsingCurrentSection() { final Section<ProjectScreenModel> section = newMockedSection(); doReturn(new ArrayList<>(singletonList(section))).when(sectionManager).getSections(); doReturn(true).when(sectionManager).manages(any()); doReturn(promises.resolve()).when(sectionManager).goToCurrentSection(); doReturn(promises.resolve()).when(presenter).setupSections(any()); doReturn(promises.resolve(true)).when(projectController).canUpdateProject(any()); presenter.setupUsingCurrentSection(); verify(view).init(eq(presenter)); verify(view).showBusyIndicator(); verify(view, never()).disableActions(); verify(projectScreenService).load(any()); verify(presenter).setupSections(any()); verify(sectionManager).goToCurrentSection(); verify(view).hideBusyIndicator(); verify(sectionManager, never()).goToFirstAvailable(); verify(notificationEvent, never()).fire(any()); }
public Promise<Void> setupUsingCurrentSection() { view.init(this); if (!projectContext.getActiveModule().isPresent()) { return promises.resolve(); } view.showBusyIndicator(); projectController.canUpdateProject(projectContext.getActiveWorkspaceProject().get()).then(userCanUpdateProject -> { if (!userCanUpdateProject) { view.disableActions(); } return promises.resolve(); }); if (pathToPom != null) { pathToPom.dispose(); } concurrentPomUpdateInfo = null; pathToPom = observablePaths.get().wrap( projectContext.getActiveModule().orElseThrow(() -> new RuntimeException("Can't get active module")).getPomXMLPath()); pathToPom.onConcurrentUpdate(info -> concurrentPomUpdateInfo = info); return promises.promisify(projectScreenService, s -> { return s.load(pathToPom); }).then(model -> { this.model = model; return setupSections(model); }).then(i -> { view.hideBusyIndicator(); if (sectionManager.manages(sectionManager.getCurrentSection())) { return sectionManager.goToCurrentSection(); } else { return sectionManager.goToFirstAvailable(); } }).catch_(o -> promises.catchOrExecute(o, e -> { view.hideBusyIndicator(); return promises.reject(e); }, i -> { notificationEvent.fire(new NotificationEvent(view.getLoadErrorMessage(), ERROR)); view.hideBusyIndicator(); return promises.resolve(); })); }
SettingsPresenter { public Promise<Void> setupUsingCurrentSection() { view.init(this); if (!projectContext.getActiveModule().isPresent()) { return promises.resolve(); } view.showBusyIndicator(); projectController.canUpdateProject(projectContext.getActiveWorkspaceProject().get()).then(userCanUpdateProject -> { if (!userCanUpdateProject) { view.disableActions(); } return promises.resolve(); }); if (pathToPom != null) { pathToPom.dispose(); } concurrentPomUpdateInfo = null; pathToPom = observablePaths.get().wrap( projectContext.getActiveModule().orElseThrow(() -> new RuntimeException("Can't get active module")).getPomXMLPath()); pathToPom.onConcurrentUpdate(info -> concurrentPomUpdateInfo = info); return promises.promisify(projectScreenService, s -> { return s.load(pathToPom); }).then(model -> { this.model = model; return setupSections(model); }).then(i -> { view.hideBusyIndicator(); if (sectionManager.manages(sectionManager.getCurrentSection())) { return sectionManager.goToCurrentSection(); } else { return sectionManager.goToFirstAvailable(); } }).catch_(o -> promises.catchOrExecute(o, e -> { view.hideBusyIndicator(); return promises.reject(e); }, i -> { notificationEvent.fire(new NotificationEvent(view.getLoadErrorMessage(), ERROR)); view.hideBusyIndicator(); return promises.resolve(); })); } }
SettingsPresenter { public Promise<Void> setupUsingCurrentSection() { view.init(this); if (!projectContext.getActiveModule().isPresent()) { return promises.resolve(); } view.showBusyIndicator(); projectController.canUpdateProject(projectContext.getActiveWorkspaceProject().get()).then(userCanUpdateProject -> { if (!userCanUpdateProject) { view.disableActions(); } return promises.resolve(); }); if (pathToPom != null) { pathToPom.dispose(); } concurrentPomUpdateInfo = null; pathToPom = observablePaths.get().wrap( projectContext.getActiveModule().orElseThrow(() -> new RuntimeException("Can't get active module")).getPomXMLPath()); pathToPom.onConcurrentUpdate(info -> concurrentPomUpdateInfo = info); return promises.promisify(projectScreenService, s -> { return s.load(pathToPom); }).then(model -> { this.model = model; return setupSections(model); }).then(i -> { view.hideBusyIndicator(); if (sectionManager.manages(sectionManager.getCurrentSection())) { return sectionManager.goToCurrentSection(); } else { return sectionManager.goToFirstAvailable(); } }).catch_(o -> promises.catchOrExecute(o, e -> { view.hideBusyIndicator(); return promises.reject(e); }, i -> { notificationEvent.fire(new NotificationEvent(view.getLoadErrorMessage(), ERROR)); view.hideBusyIndicator(); return promises.resolve(); })); } @Inject  SettingsPresenter(final View view,
                             final Promises promises,
                             final Event<NotificationEvent> notificationEvent,
                             final @Customizable SettingsSections<ProjectScreenModel> settingsSections,
                             final SavePopUpPresenter savePopUpPresenter,
                             final Caller<ProjectScreenService> projectScreenService,
                             final WorkspaceProjectContext projectContext,
                             final ManagedInstance<ObservablePath> observablePaths,
                             final ConflictingRepositoriesPopup conflictingRepositoriesPopup,
                             final SectionManager<ProjectScreenModel> sectionManager,
                             final ProjectController projectController); }
SettingsPresenter { public Promise<Void> setupUsingCurrentSection() { view.init(this); if (!projectContext.getActiveModule().isPresent()) { return promises.resolve(); } view.showBusyIndicator(); projectController.canUpdateProject(projectContext.getActiveWorkspaceProject().get()).then(userCanUpdateProject -> { if (!userCanUpdateProject) { view.disableActions(); } return promises.resolve(); }); if (pathToPom != null) { pathToPom.dispose(); } concurrentPomUpdateInfo = null; pathToPom = observablePaths.get().wrap( projectContext.getActiveModule().orElseThrow(() -> new RuntimeException("Can't get active module")).getPomXMLPath()); pathToPom.onConcurrentUpdate(info -> concurrentPomUpdateInfo = info); return promises.promisify(projectScreenService, s -> { return s.load(pathToPom); }).then(model -> { this.model = model; return setupSections(model); }).then(i -> { view.hideBusyIndicator(); if (sectionManager.manages(sectionManager.getCurrentSection())) { return sectionManager.goToCurrentSection(); } else { return sectionManager.goToFirstAvailable(); } }).catch_(o -> promises.catchOrExecute(o, e -> { view.hideBusyIndicator(); return promises.reject(e); }, i -> { notificationEvent.fire(new NotificationEvent(view.getLoadErrorMessage(), ERROR)); view.hideBusyIndicator(); return promises.resolve(); })); } @Inject  SettingsPresenter(final View view,
                             final Promises promises,
                             final Event<NotificationEvent> notificationEvent,
                             final @Customizable SettingsSections<ProjectScreenModel> settingsSections,
                             final SavePopUpPresenter savePopUpPresenter,
                             final Caller<ProjectScreenService> projectScreenService,
                             final WorkspaceProjectContext projectContext,
                             final ManagedInstance<ObservablePath> observablePaths,
                             final ConflictingRepositoriesPopup conflictingRepositoriesPopup,
                             final SectionManager<ProjectScreenModel> sectionManager,
                             final ProjectController projectController); @PostConstruct void setup(); Promise<Void> setupUsingCurrentSection(); void showSaveModal(); void onSettingsSectionChanged(@Observes final SettingsSectionChange<ProjectScreenModel> settingsSectionChange); boolean mayClose(); void reset(); View getView(); }
SettingsPresenter { public Promise<Void> setupUsingCurrentSection() { view.init(this); if (!projectContext.getActiveModule().isPresent()) { return promises.resolve(); } view.showBusyIndicator(); projectController.canUpdateProject(projectContext.getActiveWorkspaceProject().get()).then(userCanUpdateProject -> { if (!userCanUpdateProject) { view.disableActions(); } return promises.resolve(); }); if (pathToPom != null) { pathToPom.dispose(); } concurrentPomUpdateInfo = null; pathToPom = observablePaths.get().wrap( projectContext.getActiveModule().orElseThrow(() -> new RuntimeException("Can't get active module")).getPomXMLPath()); pathToPom.onConcurrentUpdate(info -> concurrentPomUpdateInfo = info); return promises.promisify(projectScreenService, s -> { return s.load(pathToPom); }).then(model -> { this.model = model; return setupSections(model); }).then(i -> { view.hideBusyIndicator(); if (sectionManager.manages(sectionManager.getCurrentSection())) { return sectionManager.goToCurrentSection(); } else { return sectionManager.goToFirstAvailable(); } }).catch_(o -> promises.catchOrExecute(o, e -> { view.hideBusyIndicator(); return promises.reject(e); }, i -> { notificationEvent.fire(new NotificationEvent(view.getLoadErrorMessage(), ERROR)); view.hideBusyIndicator(); return promises.resolve(); })); } @Inject  SettingsPresenter(final View view,
                             final Promises promises,
                             final Event<NotificationEvent> notificationEvent,
                             final @Customizable SettingsSections<ProjectScreenModel> settingsSections,
                             final SavePopUpPresenter savePopUpPresenter,
                             final Caller<ProjectScreenService> projectScreenService,
                             final WorkspaceProjectContext projectContext,
                             final ManagedInstance<ObservablePath> observablePaths,
                             final ConflictingRepositoriesPopup conflictingRepositoriesPopup,
                             final SectionManager<ProjectScreenModel> sectionManager,
                             final ProjectController projectController); @PostConstruct void setup(); Promise<Void> setupUsingCurrentSection(); void showSaveModal(); void onSettingsSectionChanged(@Observes final SettingsSectionChange<ProjectScreenModel> settingsSectionChange); boolean mayClose(); void reset(); View getView();  }