package me.artspb.idea.pitest.plugin.configuration.junit;

import com.intellij.execution.junit.JUnitConfiguration;
import com.intellij.psi.util.ClassUtil;
import me.artspb.idea.pitest.plugin.configuration.PitestConfiguration;
import org.apache.commons.lang.StringUtils;

import static me.artspb.idea.pitest.plugin.Constants.ANY_IN_PACKAGE_PATTERN;

/**
 * @author Artem Khvastunov &lt;contact@artspb.me&gt;
 */
class ClassBasedConfigurator extends Configurator {

    @Override
    public void configure(JUnitConfiguration jUnitConfiguration, PitestConfiguration configuration) {
        JUnitConfiguration.Data data = jUnitConfiguration.getPersistentData();
        String targetTests = data.getMainClassName();
        String targetClasses;
        if (StringUtils.endsWith(targetTests, "Test")) {
            targetClasses = targetTests.substring(0, targetTests.lastIndexOf("Test"));
        } else {
            targetClasses = ClassUtil.extractPackageName(targetTests) + ANY_IN_PACKAGE_PATTERN;
        }
        configure(configuration, targetTests, targetClasses);
    }
}

@@ -104,24 +104,70 @@
 figuration;%0A
+import com.intellij.openapi.util.io.FileUtil;%0A
 import com.i
@@ -780,16 +780,23 @@
 tClasses
+ = null
 ;%0A      
@@ -947,12 +947,97 @@
   %7D 
-else
+%0A        if (targetClasses == null %7C%7C FileUtil.findFirstThatExist(targetClasses) == null)
  %7B%0A 

check that a file candidate to be a target class exists