@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; }
protected ModuleBasedConfiguration createInstance() { return new JUnitConfiguration( getName(), getProject(), myData.clone(), JUnitConfigurationType.getInstance() .getConfigurationFactories()[0]); // throw new RuntimeException("Should not call"); }
private JUnitConfiguration createConfiguration(PsiPackage psiPackage, Module module) { JUnitConfiguration configuration = new JUnitConfiguration( "", myProject, JUnitConfigurationType.getInstance().getConfigurationFactories()[0]); configuration.getPersistentData().TEST_OBJECT = JUnitConfiguration.TEST_PACKAGE; configuration.getPersistentData().PACKAGE_NAME = psiPackage.getQualifiedName(); configuration.getPersistentData().setScope(TestSearchScope.WHOLE_PROJECT); configuration.setModule(module); return configuration; }
public void testExternalizeJUnitConfiguration() throws WriteExternalException, InvalidDataException { JUnitConfiguration configuration = createConfiguration(findTestA(getModule1())); Element element = new Element("cfg"); configuration.writeExternal(element); JUnitConfiguration newCfg = new JUnitConfiguration( null, myProject, JUnitConfigurationType.getInstance().getConfigurationFactories()[0]); newCfg.readExternal(element); checkTestObject(configuration.getPersistentData().TEST_OBJECT, newCfg); assertEquals( Collections.singleton(getModule1()), ContainerUtilRt.newHashSet(newCfg.getModules())); checkClassName(configuration.getPersistentData().getMainClassName(), newCfg); }
public void testRunAllInPackageWhenPackageIsEmptyInModule() throws ExecutionException { assignJdk(getModule2()); JUnitConfiguration configuration = new JUnitConfiguration( "", myProject, JUnitConfigurationType.getInstance().getConfigurationFactories()[0]); configuration.getPersistentData().TEST_OBJECT = JUnitConfiguration.TEST_PACKAGE; configuration.getPersistentData().PACKAGE_NAME = "test2"; configuration.getPersistentData().setScope(TestSearchScope.WHOLE_PROJECT); assertEmpty(configuration.getModules()); checkCanRun(configuration); configuration.getPersistentData().PACKAGE_NAME = "noTests"; // checkCantRun(configuration, "No tests found in the package '"); configuration.getPersistentData().PACKAGE_NAME = "com.abcent"; checkCantRun(configuration, "Package 'com.abcent' not found"); }
public JUnitConfigurationProducer() { super(JUnitConfigurationType.getInstance()); }