GetProjectEnvironmentsAction extends AbstractRunnerAction { @Override public void perform() { final CurrentProject currentProject = appContext.getCurrentProject(); if (currentProject == null || !runnerUtil.hasRunPermission()) { return; } final ProjectDescriptor descriptor = currentProject.getProjectDescription(); AsyncRequestCallback<RunnerEnvironmentTree> callback = callbackBuilderProvider .get() .unmarshaller(RunnerEnvironmentTree.class) .success(new SuccessCallback<RunnerEnvironmentTree>() { @Override public void onSuccess(RunnerEnvironmentTree result) { TemplatesContainer panel = templatesPanelProvider.get(); List<Environment> projectEnvironments = panel.addEnvironments(result, PROJECT); String defaultRunner = currentProject.getRunner(); if (defaultRunner != null) { defaultRunner = URL.decode(defaultRunner); setDefaultRunner(defaultRunner, projectEnvironments, panel); } chooseRunnerAction.addProjectRunners(projectEnvironments); } }) .failure(new FailureCallback() { @Override public void onFailure(@NotNull Throwable reason) { notificationManager.showError(locale.customRunnerGetEnvironmentFailed()); } }) .build(); projectService.getRunnerEnvironments(descriptor.getPath(), callback); } @Inject  GetProjectEnvironmentsAction(AppContext appContext,
                                        ProjectServiceClient projectService,
                                        NotificationManager notificationManager,
                                        Provider<AsyncCallbackBuilder<RunnerEnvironmentTree>> callbackBuilderProvider,
                                        RunnerLocalizationConstant locale,
                                        RunnerUtil runnerUtil,
                                        ChooseRunnerAction chooseRunnerAction,
                                        Provider<TemplatesContainer> templatesPanelProvider); @Override void perform();  }
@Test public void shouldNotPerformWhenCurrentProjectIsNull() { when(appContext.getCurrentProject()).thenReturn(null); action.perform(); verify(appContext).getCurrentProject(); verifyNoMoreInteractions(appContext, projectService, notificationManager, callbackBuilderProvider, locale, runnerUtil, chooseRunnerAction, templatesContainerProvider, project); }
@Test public void shouldNotPerformWhenCurrentProjectIsNotNullAndProjectDoesNotHavePermission() { when(runnerUtil.hasRunPermission()).thenReturn(false); action.perform(); verify(appContext).getCurrentProject(); verify(runnerUtil).hasRunPermission(); verifyNoMoreInteractions(appContext, projectService, notificationManager, callbackBuilderProvider, locale, runnerUtil, chooseRunnerAction, templatesContainerProvider, project); }
@Test public void shouldPerformFailure() { String errorMessage = "error message"; when(locale.customRunnerGetEnvironmentFailed()).thenReturn(errorMessage); action.perform(); verify(appContext).getCurrentProject(); verify(asyncCallbackBuilder).failure(failedCallBackCaptor.capture()); FailureCallback failureCallback = failedCallBackCaptor.getValue(); failureCallback.onFailure(reason); verify(locale).customRunnerGetEnvironmentFailed(); verify(notificationManager).showError(errorMessage); verify(projectService).getRunnerEnvironments(SOME_STRING, asyncRequestCallback); }
@Test public void shouldPerformSuccessWithToRunnerEnvironment() { when(appContext.getCurrentProject()).thenReturn(currentProject); when(currentProject.getProjectDescription()).thenReturn(descriptor); when(currentProject.getRunner()).thenReturn(SOME_STRING); when(descriptor.getPath()).thenReturn(SOME_STRING); when(descriptor.getType()).thenReturn(SOME_STRING); action.perform(); verify(appContext).getCurrentProject(); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); }
@Test public void shouldPerformSuccessWithToRunnerEnvironmentButDefaultRunnerIsNotExist() { when(appContext.getCurrentProject()).thenReturn(currentProject); when(currentProject.getProjectDescription()).thenReturn(descriptor); when(currentProject.getRunner()).thenReturn(SOME_STRING + 1); when(descriptor.getPath()).thenReturn(SOME_STRING); when(descriptor.getType()).thenReturn(SOME_STRING); action.perform(); verify(appContext).getCurrentProject(); verify(asyncCallbackBuilder).success(successCallBackCaptor.capture()); }