terminate all running descriptors
[idea/community.git] / platform / lang-impl / testSources / com / intellij / execution / impl / ExecutionManagerTest.java
index b6032ee4363148041912bd940e26a274b068c593..eaf0592753b0f89aae3eab64d9bf0b1bc9edfbe0 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.execution.impl;
 
+import com.intellij.execution.ExecutionManager;
 import com.intellij.execution.RunManagerConfig;
 import com.intellij.execution.RunnerAndConfigurationSettings;
 import com.intellij.execution.executors.DefaultRunExecutor;
@@ -23,16 +24,10 @@ import com.intellij.execution.runners.ExecutionEnvironment;
 import com.intellij.execution.runners.ExecutionEnvironmentBuilder;
 import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Conditions;
-import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.testFramework.LightPlatformTestCase;
-import com.intellij.util.Function;
-import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NotNull;
 
-import java.util.List;
-
 public class ExecutionManagerTest extends LightPlatformTestCase {
 
   private boolean myRestartRequiresConfirmation;
@@ -48,6 +43,7 @@ public class ExecutionManagerTest extends LightPlatformTestCase {
   @Override
   public void tearDown() throws Exception {
     try {
+      ExecutionTestUtil.terminateAllRunningDescriptors(ExecutionManager.getInstance(getProject()));
       RunManagerConfig config = RunManagerImpl.getInstanceImpl(getProject()).getConfig();
       config.setRestartRequiresConfirmation(myRestartRequiresConfirmation);
     }
@@ -92,33 +88,13 @@ public class ExecutionManagerTest extends LightPlatformTestCase {
 
   @NotNull
   private static FakeProcessHandler getProcessHandler(@NotNull ExecutionManagerImpl executionManager) {
-    List<RunContentDescriptor> descriptors = executionManager.getRunningDescriptors(Conditions.alwaysTrue());
-    String actualDescriptorsMsg = stringifyDescriptors(descriptors);
-    assertEquals(actualDescriptorsMsg, 1, descriptors.size());
-    RunContentDescriptor descriptor = ContainerUtil.getFirstItem(descriptors);
-    assertNotNull(actualDescriptorsMsg, descriptor);
+    RunContentDescriptor descriptor = ExecutionTestUtil.getSingleRunContentDescriptor(executionManager);
     ProcessHandler processHandler = descriptor.getProcessHandler();
-    assertNotNull(actualDescriptorsMsg, processHandler);
+    assertNotNull(processHandler);
     return (FakeProcessHandler)processHandler;
   }
 
   @NotNull
-  private static String stringifyDescriptors(@NotNull List<RunContentDescriptor> descriptors) {
-    return "Actual descriptors: " + StringUtil.join(descriptors, new Function<RunContentDescriptor, String>() {
-      @Override
-      public String fun(RunContentDescriptor descriptor) {
-        if (descriptor == null) {
-          return "null";
-        }
-        ProcessHandler processHandler = descriptor.getProcessHandler();
-        return String.format("[%s, %s]",
-                             descriptor.getDisplayName(),
-                             processHandler != null ? processHandler.getClass().getName() : null);
-      }
-    }, ", ");
-  }
-
-  @NotNull
   private static ExecutionEnvironment createEnv(@NotNull Project project, @NotNull RunnerAndConfigurationSettings settings) {
     return new ExecutionEnvironmentBuilder(project, DefaultRunExecutor.getRunExecutorInstance())
       .runnerAndSettings(FakeProgramRunner.INSTANCE, settings)