@Override
  public boolean isConfigurationFromContext(
      JUnitConfiguration unitConfiguration, ConfigurationContext context) {
    if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class)
        .isMultipleElementsSelected(context)) {
      return false;
    }
    final RunConfiguration predefinedConfiguration =
        context.getOriginalConfiguration(JUnitConfigurationType.getInstance());
    final Location contextLocation = context.getLocation();

    String paramSetName =
        contextLocation instanceof PsiMemberParameterizedLocation
            ? ((PsiMemberParameterizedLocation) contextLocation).getParamSetName()
            : null;
    assert contextLocation != null;
    Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation);
    if (location == null) {
      return false;
    }
    final PsiElement element = location.getPsiElement();
    final PsiClass testClass = JUnitUtil.getTestClass(element);
    final PsiMethod testMethod = JUnitUtil.getTestMethod(element, false);
    final PsiPackage testPackage;
    if (element instanceof PsiPackage) {
      testPackage = (PsiPackage) element;
    } else if (element instanceof PsiDirectory) {
      testPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) element));
    } else {
      testPackage = null;
    }
    PsiDirectory testDir = element instanceof PsiDirectory ? (PsiDirectory) element : null;
    RunnerAndConfigurationSettings template =
        RunManager.getInstance(location.getProject())
            .getConfigurationTemplate(getConfigurationFactory());
    final Module predefinedModule =
        ((JUnitConfiguration) template.getConfiguration()).getConfigurationModule().getModule();
    final String vmParameters =
        predefinedConfiguration instanceof JUnitConfiguration
            ? ((JUnitConfiguration) predefinedConfiguration).getVMParameters()
            : null;

    if (vmParameters != null
        && !Comparing.strEqual(vmParameters, unitConfiguration.getVMParameters())) return false;
    if (paramSetName != null
        && !Comparing.strEqual(paramSetName, unitConfiguration.getProgramParameters()))
      return false;
    final TestObject testobject = unitConfiguration.getTestObject();
    if (testobject != null) {
      if (testobject.isConfiguredByElement(
          unitConfiguration, testClass, testMethod, testPackage, testDir)) {
        final Module configurationModule = unitConfiguration.getConfigurationModule().getModule();
        if (Comparing.equal(location.getModule(), configurationModule)) return true;
        if (Comparing.equal(predefinedModule, configurationModule)) {
          return true;
        }
      }
    }
    return false;
  }
 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);
 }
 public void testCantCreateConfiguration() {
   PsiClass objectClass =
       JavaPsiFacade.getInstance(myProject)
           .findClass(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(myProject));
   assertNull(createConfiguration(objectClass));
   assertNull(createConfiguration(JUnitUtil.getContainingPackage(objectClass)));
 }
  protected Condition<PsiClass> getConditionToSearchForInheritors() {
    return psiClass -> {
      if (psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
        return true;
      }

      if (JUnitUtil.isTestCaseInheritor(psiClass)) {
        final PsiMethod[] constructors = psiClass.getConstructors();
        for (PsiMethod method : constructors) {
          if (method.getParameterList().getParametersCount() == 0) {
            return false;
          }
        }
        return constructors.length != 0;
      }

      return false;
    };
  }
 public Module setMainClass(final PsiClass testClass) {
   MAIN_CLASS_NAME = JavaExecutionUtil.getRuntimeQualifiedName(testClass);
   PsiPackage containingPackage = JUnitUtil.getContainingPackage(testClass);
   PACKAGE_NAME = containingPackage != null ? containingPackage.getQualifiedName() : "";
   return JavaExecutionUtil.findModule(testClass);
 }