TemplatesPresenter implements TemplatesContainer, FilterWidget.ActionDelegate, TemplatesView.ActionDelegate { @Override public void setDefaultEnvironment(@Nullable Environment environment) { this.defaultEnvironment = environment; CurrentProject currentProject = getCurrentProject(); ProjectDescriptor descriptor = currentProject.getProjectDescription(); if (environment == null) { descriptor.getRunners().setDefault(null); updateProject(descriptor, null); return; } String defaultRunner = currentProject.getRunner(); String environmentId = environment.getId(); if (!EnvironmentIdValidator.isValid(environmentId)) { environmentId = URL.encode(environmentId); } if (!environmentId.equals(defaultRunner)) { descriptor.getRunners().setDefault(environmentId); updateProject(descriptor, defaultEnvWidget); defaultEnvWidget.update(environment); return; } defaultEnvWidget.update(environment); view.setDefaultProjectWidget(defaultEnvWidget); } @Inject  TemplatesPresenter(TemplatesView view,
                              FilterWidget filter,
                              EnvironmentWidget defaultEnvWidget,
                              AppContext appContext,
                              GetProjectEnvironmentsAction projectEnvironmentsAction,
                              GetSystemEnvironmentsAction systemEnvironmentsAction,
                              GetEnvironmentsUtil environmentUtil,
                              PropertiesContainer propertiesContainer,
                              SelectionManager selectionManager,
                              AsyncCallbackBuilder<ItemReference> asyncCallbackBuilder,
                              RunnerManagerView runnerManagerView,
                              NotificationManager notificationManager,
                              RunnerUtil runnerUtil,
                              RunnerResources resources,
                              PanelState panelState,
                              ProjectServiceClient projectService,
                              AsyncCallbackBuilder<ProjectDescriptor> asyncDescriptorCallbackBuilder,
                              ChooseRunnerAction chooseRunnerAction); @Override void select(@Nullable Environment environment); @Override List<Environment> addEnvironments(@NotNull RunnerEnvironmentTree tree, @NotNull Scope scope); @NotNull List<Environment> getProjectEnvironments(); @Override void showEnvironments(); @Override void selectEnvironment(); @Override void onValueChanged(); @Override void changeEnableStateRunButton(); @Override void setDefaultEnvironment(@Nullable Environment environment); @Override void onDefaultRunnerMouseOver(); @Override void createNewEnvironment(); @Override void go(@NotNull AcceptsOneWidget container); @NotNull @Override IsWidget getView(); @Override void setVisible(boolean visible);  }
@Test public void defaultEnvironmentShouldNotBeSetWhenDefaultRunnerIsChanged() throws Exception { when(environment.getId()).thenReturn("project:/runner"); presenter.setDefaultEnvironment(environment); verify(currentProject).getRunner(); verify(defaultEnvWidget).update(environment); verify(environment).getId(); verify(descriptor).getRunners(); verify(runnersDescriptor).setDefault("project:/runner"); updateProjectShouldBeVerified(); verify(defaultEnvWidget).update(environment); }