use of com.intellij.execution.junit2.PsiMemberParameterizedLocation in project android by JetBrains.
the class TestMethodAndroidConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(JUnitConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
return false;
}
final Location contextLocation = context.getLocation();
assert contextLocation != null;
Location<PsiMethod> methodLocation = getTestMethod(contextLocation);
if (methodLocation == null)
return false;
if (contextLocation instanceof PsiMemberParameterizedLocation) {
final String paramSetName = ((PsiMemberParameterizedLocation) contextLocation).getParamSetName();
if (paramSetName != null) {
configuration.setProgramParameters(paramSetName);
}
PsiClass containingClass = ((PsiMemberParameterizedLocation) contextLocation).getContainingClass();
if (containingClass != null) {
methodLocation = MethodLocation.elementInClass(methodLocation.getPsiElement(), containingClass);
}
}
sourceElement.set(methodLocation.getPsiElement());
setupConfigurationModule(context, configuration);
final Module originalModule = configuration.getConfigurationModule().getModule();
configuration.beMethodConfiguration(methodLocation);
configuration.restoreOriginalModule(originalModule);
JavaRunConfigurationExtensionManager.getInstance().extendCreatedConfiguration(configuration, contextLocation);
configuration.setForkMode(JUnitConfiguration.FORK_NONE);
return true;
}
use of com.intellij.execution.junit2.PsiMemberParameterizedLocation in project intellij-community by JetBrains.
the class PatternConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(JUnitConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
final LinkedHashSet<String> classes = new LinkedHashSet<>();
final PsiElement element = checkPatterns(context, classes);
if (element == null) {
return false;
}
sourceElement.set(element);
final JUnitConfiguration.Data data = configuration.getPersistentData();
data.setPatterns(classes);
data.TEST_OBJECT = JUnitConfiguration.TEST_PATTERN;
data.setScope(setupPackageConfiguration(context, configuration, data.getScope()));
configuration.setGeneratedName();
final Location contextLocation = context.getLocation();
if (contextLocation instanceof PsiMemberParameterizedLocation) {
final String paramSetName = ((PsiMemberParameterizedLocation) contextLocation).getParamSetName();
if (paramSetName != null) {
configuration.setProgramParameters(paramSetName);
}
}
return true;
}
use of com.intellij.execution.junit2.PsiMemberParameterizedLocation in project intellij-community by JetBrains.
the class JUnitRerunFailedTestsTest method testParameterizedTestNavigation.
public void testParameterizedTestNavigation() throws Exception {
myFixture.addClass("package org.junit.runner;\n" + "public @interface RunWith {\n" + " Class<? extends Runner> value();\n" + "}");
myFixture.addClass("package org.junit.runners; public class Parameterized {}");
final PsiClass testClass = myFixture.addClass("import org.junit.Test;\n" + "import org.junit.runner.RunWith;\n" + "import org.junit.runners.Parameterized;\n" + "@RunWith(Parameterized.class)\n" + "public class MyTest {\n" + " @Test\n" + " public void testName1() throws Exception {}\n" + "}");
final Project project = getProject();
final GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
final JavaTestLocator locationProvider = JavaTestLocator.INSTANCE;
final SMTestProxy rootProxy = new SMTestProxy("MyTest", true, "java:suite://MyTest");
rootProxy.setLocator(locationProvider);
final SMTestProxy proxyParam = new SMTestProxy("[0.java]", true, "java:suite://MyTest.[0.java]");
proxyParam.setLocator(locationProvider);
final SMTestProxy parameterizedTestProxy = new SMTestProxy("testName1[0.java]", false, "java:test://MyTest.testName1[0.java]");
parameterizedTestProxy.setLocator(locationProvider);
final Location rootLocation = rootProxy.getLocation(project, searchScope);
assertNotNull(rootLocation);
assertEquals(testClass, rootLocation.getPsiElement());
final Location proxyParamLocation = proxyParam.getLocation(project, searchScope);
assertNotNull(proxyParamLocation);
assertInstanceOf(proxyParamLocation, PsiMemberParameterizedLocation.class);
assertEquals("[0.java]", ((PsiMemberParameterizedLocation) proxyParamLocation).getParamSetName());
assertEquals(testClass, proxyParamLocation.getPsiElement());
final Location parameterizedTestProxyLocation = parameterizedTestProxy.getLocation(project, searchScope);
assertNotNull(parameterizedTestProxyLocation);
assertInstanceOf(parameterizedTestProxyLocation, PsiMemberParameterizedLocation.class);
assertEquals("[0.java]", ((PsiMemberParameterizedLocation) parameterizedTestProxyLocation).getParamSetName());
assertEquals(testClass.getMethods()[0], parameterizedTestProxyLocation.getPsiElement());
assertEquals(testClass, ((PsiMemberParameterizedLocation) parameterizedTestProxyLocation).getContainingClass());
assertEquals("MyTest,testName1[0.java]", TestMethods.getTestPresentation(parameterizedTestProxy, project, searchScope));
}
use of com.intellij.execution.junit2.PsiMemberParameterizedLocation in project intellij-community by JetBrains.
the class AbstractJavaTestConfigurationProducer method isConfigurationFromContext.
@Override
public boolean isConfigurationFromContext(T configuration, ConfigurationContext context) {
if (isMultipleElementsSelected(context)) {
return false;
}
final RunConfiguration predefinedConfiguration = context.getOriginalConfiguration(getConfigurationType());
final Location contextLocation = context.getLocation();
if (contextLocation == null) {
return false;
}
Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation);
if (location == null) {
return false;
}
final PsiElement element = location.getPsiElement();
RunnerAndConfigurationSettings template = RunManager.getInstance(location.getProject()).getConfigurationTemplate(getConfigurationFactory());
final Module predefinedModule = ((T) template.getConfiguration()).getConfigurationModule().getModule();
final String vmParameters = predefinedConfiguration instanceof CommonJavaRunConfigurationParameters ? ((CommonJavaRunConfigurationParameters) predefinedConfiguration).getVMParameters() : null;
if (vmParameters != null && !Comparing.strEqual(vmParameters, configuration.getVMParameters()))
return false;
String paramSetName = contextLocation instanceof PsiMemberParameterizedLocation ? configuration.prepareParameterizedParameter(((PsiMemberParameterizedLocation) contextLocation).getParamSetName()) : null;
if (paramSetName != null && !Comparing.strEqual(paramSetName, configuration.getProgramParameters()))
return false;
if (configuration.isConfiguredByElement(element)) {
final Module configurationModule = configuration.getConfigurationModule().getModule();
if (Comparing.equal(location.getModule(), configurationModule))
return true;
if (Comparing.equal(predefinedModule, configurationModule))
return true;
}
return false;
}
use of com.intellij.execution.junit2.PsiMemberParameterizedLocation in project intellij by bazelbuild.
the class BlazeJUnitTestFilterFlags method testFilterForLocation.
private static String testFilterForLocation(Location<?> location) {
PsiElement psi = location.getPsiElement();
assert (psi instanceof PsiMethod);
String methodName = ((PsiMethod) psi).getName();
if (location instanceof PsiMemberParameterizedLocation) {
return methodName + StringUtil.escapeToRegexp(((PsiMemberParameterizedLocation) location).getParamSetName());
}
return methodName;
}
Aggregations