コード例 #1
0
 public void bePatternConfiguration(List<PsiClass> classes, PsiMethod method) {
   data.TEST_OBJECT = TestType.PATTERN.getType();
   final String suffix;
   if (method != null) {
     data.METHOD_NAME = method.getName();
     suffix = "," + data.METHOD_NAME;
   } else {
     suffix = "";
   }
   LinkedHashSet<String> patterns = new LinkedHashSet<String>();
   for (PsiClass pattern : classes) {
     patterns.add(JavaExecutionUtil.getRuntimeQualifiedName(pattern) + suffix);
   }
   data.setPatterns(patterns);
   final Module module =
       RunConfigurationProducer.getInstance(TestNGPatternConfigurationProducer.class)
           .findModule(this, getConfigurationModule().getModule(), patterns);
   if (module == null) {
     data.setScope(TestSearchScope.WHOLE_PROJECT);
     setModule(null);
   } else {
     setModule(module);
   }
   setGeneratedName();
 }
コード例 #2
0
  @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;
  }
 @Override
 @NotNull
 protected TestNGPatternConfigurationProducer getPatternBasedProducer() {
   return RunConfigurationProducer.getInstance(TestNGPatternConfigurationProducer.class);
 }