RunAction extends AbstractRunnerActions { @Override public void actionPerformed(@NotNull ActionEvent event) { eventLogger.log(this); CurrentProject currentProject = appContext.getCurrentProject(); if (currentProject == null) { return; } String defaultRunner = currentProject.getRunner(); Environment environment = chooseRunnerAction.selectEnvironment(); if (environment == null && defaultRunner == null) { notificationManager.showError(locale.actionRunnerNotSpecified()); } if (environment == null || (defaultRunner != null && defaultRunner.equals(environment.getId()))) { runnerManager.launchRunner(); } else { RunOptions runOptions = dtoFactory.createDto(RunOptions.class) .withOptions(environment.getOptions()) .withEnvironmentId(environment.getId()) .withMemorySize(environment.getRam()); runnerManager.launchRunner(runOptions, environment.getScope(), environment.getName()); } } @Inject  RunAction(RunnerManager runnerManager,
                     RunnerLocalizationConstant locale,
                     AppContext appContext,
                     NotificationManager notificationManager,
                     ChooseRunnerAction chooseRunnerAction,
                     DtoFactory dtoFactory,
                     RunnerResources resources,
                     AnalyticsEventLogger eventLogger); @Override void actionPerformed(@NotNull ActionEvent event);  }
@Test public void actionShouldNotBePerformedIfCurrentProjectIsNull() throws Exception { when(appContext.getCurrentProject()).thenReturn(null); action.actionPerformed(actionEvent); verify(eventLogger).log(action); verify(runnerManager, never()).launchRunner(); verify(runnerManager, never()).launchRunner(Matchers.<RunOptions>any(), Matchers.<Scope>any(),anyString()); }
@Test public void actionShouldBeLaunchDefaultRunner1() throws Exception { when(chooseRunnerAction.selectEnvironment()).thenReturn(null); when(appContext.getCurrentProject()).thenReturn(currentProject); when(currentProject.getRunner()).thenReturn('/' + SOME_STRING); when(environment.getName()).thenReturn(SOME_STRING); action.actionPerformed(actionEvent); verify(eventLogger).log(action); verify(runnerManager).launchRunner(); }
@Test public void actionShouldBeLaunchDefaultRunner2() throws Exception { when(chooseRunnerAction.selectEnvironment()).thenReturn(environment); when(appContext.getCurrentProject()).thenReturn(currentProject); when(currentProject.getRunner()).thenReturn(SOME_STRING); when(environment.getId()).thenReturn(SOME_STRING); when(environment.getName()).thenReturn(SOME_STRING); action.actionPerformed(actionEvent); verify(eventLogger).log(action); verify(runnerManager).launchRunner(); }
@Test public void actionShouldBeLaunchDefaultRunnerIfEnvironmentIsNull() throws Exception { when(currentProject.getRunner()).thenReturn(SOME_STRING); when(chooseRunnerAction.selectEnvironment()).thenReturn(null); when(appContext.getCurrentProject()).thenReturn(currentProject); action.actionPerformed(actionEvent); verify(eventLogger).log(action); verify(runnerManager).launchRunner(); }
@Test public void actionShouldBeLaunchCustomEnvironment() throws Exception { when(chooseRunnerAction.selectEnvironment()).thenReturn(environment); when(environment.getScope()).thenReturn(SYSTEM); when(appContext.getCurrentProject()).thenReturn(currentProject); when(currentProject.getRunner()).thenReturn(SOME_STRING + SOME_STRING); when(environment.getName()).thenReturn(SOME_STRING); when(environment.getId()).thenReturn(SOME_STRING); when(environment.getRam()).thenReturn(MB_200.getValue()); when(dtoFactory.createDto(RunOptions.class)).thenReturn(runOptions); when(runOptions.withOptions(Matchers.<Map<String, String>>any())).thenReturn(runOptions); when(runOptions.withEnvironmentId(anyString())).thenReturn(runOptions); when(runOptions.withMemorySize(MB_200.getValue())).thenReturn(runOptions); action.actionPerformed(actionEvent); verify(eventLogger).log(action); verify(environment).getOptions(); verify(environment, times(2)).getId(); verify(environment).getRam(); verify(environment).getName(); verify(dtoFactory).createDto(RunOptions.class); verify(runOptions).withOptions(Matchers.<Map<String, String>>any()); verify(runOptions).withEnvironmentId(anyString()); verify(runOptions).withMemorySize(MB_200.getValue()); verify(runOptions).withOptions(Matchers.<Map<String, String>>any()); verify(runnerManager).launchRunner(runOptions, SYSTEM, SOME_STRING); }
@Test public void notificationShouldBeShownWhenRunnerIsNotSpecified() throws Exception { when(appContext.getCurrentProject()).thenReturn(currentProject); when(locale.actionRunnerNotSpecified()).thenReturn(SOME_STRING); when(currentProject.getRunner()).thenReturn(null); action.actionPerformed(actionEvent); verify(eventLogger).log(action); verify(locale).actionRunnerNotSpecified(); verify(notificationManager).showError(SOME_STRING); }