public void testAllInPackageForProject() throws IOException, ExecutionException {
    // module1 -> module2 -> module3
    // module5
    addModule("module5");
    addDependency(getModule1(), getModule2());
    addDependency(getModule2(), getModule3());
    String[][] outputs = new String[4][];
    for (int i = 0; i < 4; i++) {
      outputs[i] = addOutputs(getModule(i), i + 1);
    }

    PsiPackage defaultPackage = JavaPsiFacade.getInstance(myProject).findPackage("");
    JUnitConfiguration configuration =
        createJUnitConfiguration(
            defaultPackage, AllInPackageConfigurationProducer.class, new MapDataContext());
    configuration.getPersistentData().setScope(TestSearchScope.WHOLE_PROJECT);
    JavaParameters javaParameters = checkCanRun(configuration);
    String classPath = javaParameters.getClassPath().getPathsString();
    assertEquals(-1, classPath.indexOf(JarFileSystem.PROTOCOL_PREFIX));
    assertEquals(-1, classPath.indexOf(LocalFileSystem.PROTOCOL_PREFIX));
    for (int i = 0; i < 4; i++) {
      checkContains(classPath, outputs[i][0]);
      checkContains(classPath, outputs[i][1]);
    }
  }
  public void testTestClassPathWhenRunningConfigurations() throws IOException, ExecutionException {
    addModule("module4", false);
    Module module4 = getModule4();
    assignJdk(module4);
    addSourcePath(module4, "testSrc", true);
    addSourcePath(module4, "src", false);
    String output = setCompilerOutput(module4, "classes", false);
    String testOuput = setCompilerOutput(module4, "testClasses", true);

    ApplicationConfiguration applicationConfiguration =
        createConfiguration(findClass(module4, "Application"));
    JavaParameters parameters = checkCanRun(applicationConfiguration);
    String classPath = parameters.getClassPath().getPathsString();
    checkDoesNotContain(classPath, testOuput);
    checkContains(classPath, output);

    JUnitConfiguration junitConfiguration =
        createJUnitConfiguration(
            findClass(module4, "TestApplication"),
            TestClassConfigurationProducer.class,
            new MapDataContext());
    parameters = checkCanRun(junitConfiguration);
    classPath = parameters.getClassPath().getPathsString();
    checkContains(classPath, testOuput);
    checkContains(classPath, output);

    applicationConfiguration.MAIN_CLASS_NAME =
        junitConfiguration.getPersistentData().getMainClassName();
    classPath = checkCanRun(applicationConfiguration).getClassPath().getPathsString();
    checkContains(classPath, testOuput);
    checkContains(classPath, output);
  }
 public void testClasspathConfiguration() throws CantRunException {
   JavaParameters parameters = new JavaParameters();
   RunConfigurationModule module = new JavaRunConfigurationModule(myProject, false);
   Module module1 = getModule1();
   Module module2 = getModule2();
   addDependency(module1, module2);
   Module module3 = getModule3();
   addDependency(module2, module3);
   addDependency(module1, module3);
   addOutputs(module1, 1);
   addOutputs(module2, 2);
   addOutputs(module3, 3);
   module.setModule(module1);
   parameters.configureByModule(module.getModule(), JavaParameters.JDK_AND_CLASSES_AND_TESTS);
   ArrayList<String> classPath = new ArrayList<>();
   StringTokenizer tokenizer =
       new StringTokenizer(parameters.getClassPath().getPathsString(), File.pathSeparator);
   while (tokenizer.hasMoreTokens()) {
     String token = tokenizer.nextToken();
     classPath.add(token);
   }
   CHECK.singleOccurence(classPath, getOutput(module1, false));
   CHECK.singleOccurence(classPath, getOutput(module1, false));
   CHECK.singleOccurence(classPath, getOutput(module1, true));
   CHECK.singleOccurence(classPath, getOutput(module2, false));
   CHECK.singleOccurence(classPath, getOutput(module2, true));
   CHECK.singleOccurence(classPath, getOutput(module3, false));
   CHECK.singleOccurence(classPath, getOutput(module3, true));
   CHECK.singleOccurence(classPath, getFSPath(findFile(MOCK_JUNIT)));
 }
  public void testSameTestAndCommonOutput() throws IOException, ExecutionException {
    addModule("module4", false);
    Module module = getModule4();
    assignJdk(module);
    addSourcePath(module, "src", false);
    addSourcePath(module, "testSrc", false);
    String output = setCompilerOutput(module, "classes", false);
    assertEquals(output, setCompilerOutput(module, "classes", true));

    RunConfiguration configuration = createConfiguration(findClass(module, "Application"));
    JavaParameters javaParameters = checkCanRun(configuration);
    checkContains(javaParameters.getClassPath().getPathsString(), output);

    configuration = createConfiguration(findClass(module, "TestApplication"));
    javaParameters = checkCanRun(configuration);
    checkContains(javaParameters.getClassPath().getPathsString(), output);
  }
 private static List<String> extractAllInPackageTests(
     JavaParameters parameters, PsiPackage psiPackage) throws IOException {
   String filePath =
       ContainerUtil.find(
               parameters.getProgramParametersList().getArray(),
               value ->
                   StringUtil.startsWithChar(value, '@') && !StringUtil.startsWith(value, "@w@"))
           .substring(1);
   List<String> lines = readLinesFrom(new File(filePath));
   assertEquals(psiPackage.getQualifiedName(), lines.get(0));
   // lines.remove(0);
   lines.remove(0);
   return lines;
 }
 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());
 }