public void testRunningJUnit() throws ExecutionException {
   PsiClass testA = findTestA(getModule1());
   JUnitConfiguration configuration = createConfiguration(testA);
   JavaParameters parameters = checkCanRun(configuration);
   assertEmpty(parameters.getVMParametersList().getList());
   final SegmentedOutputStream notifications = new SegmentedOutputStream(System.out);
   assertTrue(
       JUnitStarter.checkVersion(
           parameters.getProgramParametersList().getArray(), new PrintStream(notifications)));
   assertTrue(parameters.getProgramParametersList().getList().contains(testA.getQualifiedName()));
   assertEquals(JUnitStarter.class.getName(), parameters.getMainClass());
   assertEquals(myJdk.getHomeDirectory().getPresentableUrl(), parameters.getJdkPath());
 }
  public void testCreateConfiguration() throws IOException, ExecutionException {
    Module module1 = getModule1();
    PsiClass psiClass = findTestA(module1);
    JUnitConfiguration configuration = createConfiguration(psiClass);
    assertEquals(
        Collections.singleton(module1), ContainerUtilRt.newHashSet(configuration.getModules()));
    checkClassName(psiClass.getQualifiedName(), configuration);
    assertEquals(psiClass.getName(), configuration.getName());
    checkTestObject(JUnitConfiguration.TEST_CLASS, configuration);
    Module module2 = getModule2();
    Assertion.compareUnordered(new Module[] {module1, module2}, configuration.getValidModules());

    PsiClass innerTest = findClass(module1, INNER_TEST_NAME);
    configuration =
        createJUnitConfiguration(
            innerTest, TestClassConfigurationProducer.class, new MapDataContext());
    checkClassName(RT_INNER_TEST_NAME, configuration);
    checkCanRun(configuration);

    PsiMethod[] testMethod = innerTest.findMethodsByName("test", false);
    assertEquals(1, testMethod.length);
    configuration = createConfiguration(testMethod[0]);
    checkClassName(RT_INNER_TEST_NAME, configuration);
    checkMethodName("test", configuration);
    checkTestObject(JUnitConfiguration.TEST_METHOD, configuration);
    checkCanRun(configuration);

    PsiMethod mainMethod = innerTest.findMethodsByName("main", false)[0];
    ApplicationConfiguration appConfiguration = createConfiguration(mainMethod);
    assertEquals(RT_INNER_TEST_NAME, appConfiguration.MAIN_CLASS_NAME);
    checkCanRun(configuration);
  }
  public void testEditJUnitConfiguration() throws ConfigurationException {
    if (PlatformTestUtil.COVERAGE_ENABLED_BUILD) return;

    PsiClass testA = findTestA(getModule2());
    JUnitConfiguration configuration = createConfiguration(testA);
    JUnitConfigurable editor = new JUnitConfigurable(myProject);
    try {
      Configurable configurable = new RunConfigurationConfigurableAdapter(editor, configuration);
      configurable.reset();
      final EditorTextFieldWithBrowseButton component =
          ((LabeledComponent<EditorTextFieldWithBrowseButton>)
                  editor.getTestLocation(JUnitConfigurationModel.CLASS))
              .getComponent();
      assertEquals(testA.getQualifiedName(), component.getText());
      PsiClass otherTest = findClass(getModule2(), "test2.Test2");
      component.setText(otherTest.getQualifiedName());
      configurable.apply();
      assertEquals(otherTest.getName(), configuration.getName());
      String specialName = "My name";
      configuration.setName(specialName);
      configuration.setNameChangedByUser(true);
      configurable.reset();
      component.setText(testA.getQualifiedName());
      configurable.apply();
      assertEquals(specialName, configuration.getName());
    } finally {
      Disposer.dispose(editor);
    }
  }
 public void testRunningAllInPackage() throws IOException, ExecutionException {
   Module module1 = getModule1();
   GlobalSearchScope module1AndLibraries = GlobalSearchScope.moduleWithLibrariesScope(module1);
   PsiClass testCase = findClass(TestCase.class.getName(), module1AndLibraries);
   PsiClass psiClass = findTestA(module1);
   PsiClass psiClass2 = findTestA(getModule2());
   PsiClass derivedTest = findClass(module1, "test1.DerivedTest");
   PsiClass baseTestCase = findClass("junit.framework.ThirdPartyClass", module1AndLibraries);
   PsiClass testB = findClass(getModule3(), "test1.TestB");
   assertNotNull(testCase);
   assertNotNull(derivedTest);
   assertNotNull(psiClass);
   assertTrue(psiClass.isInheritor(testCase, false));
   assertEquals(baseTestCase, derivedTest.getSuperClass());
   assertTrue(baseTestCase.isInheritor(testCase, true));
   assertTrue(derivedTest.isInheritor(testCase, true));
   PsiPackage psiPackage = JUnitUtil.getContainingPackage(psiClass);
   JUnitConfiguration configuration = createConfiguration(psiPackage, module1);
   JavaParameters parameters = checkCanRun(configuration);
   List<String> lines = extractAllInPackageTests(parameters, psiPackage);
   Assertion.compareUnordered(
       new Object[] {
         "",
         psiClass.getQualifiedName(),
         psiClass2.getQualifiedName(),
         derivedTest.getQualifiedName(),
         RT_INNER_TEST_NAME,
         testB.getQualifiedName()
       },
       lines);
 }