Search in sources :

Example 6 with PsiMemberParameterizedLocation

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;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) Module(com.intellij.openapi.module.Module) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation)

Example 7 with PsiMemberParameterizedLocation

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PsiElement(com.intellij.psi.PsiElement) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) Location(com.intellij.execution.Location) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation)

Example 8 with PsiMemberParameterizedLocation

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));
}
Also used : Project(com.intellij.openapi.project.Project) SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) JavaTestLocator(com.intellij.execution.testframework.JavaTestLocator) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location)

Example 9 with PsiMemberParameterizedLocation

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;
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) Module(com.intellij.openapi.module.Module) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation)

Example 10 with PsiMemberParameterizedLocation

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;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiElement(com.intellij.psi.PsiElement) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation)

Aggregations

PsiMemberParameterizedLocation (com.intellij.execution.junit2.PsiMemberParameterizedLocation)12 Location (com.intellij.execution.Location)8 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)6 PsiClass (com.intellij.psi.PsiClass)6 PsiMethod (com.intellij.psi.PsiMethod)6 PsiElement (com.intellij.psi.PsiElement)4 Module (com.intellij.openapi.module.Module)3 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)2 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)2 PsiFile (com.intellij.psi.PsiFile)2 LinkedHashSet (java.util.LinkedHashSet)2 Test (org.junit.Test)2 PsiLocation (com.intellij.execution.PsiLocation)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)1 JUnitConfiguration (com.intellij.execution.junit.JUnitConfiguration)1 PatternConfigurationProducer (com.intellij.execution.junit.PatternConfigurationProducer)1 TestObject (com.intellij.execution.junit.TestObject)1 JavaTestLocator (com.intellij.execution.testframework.JavaTestLocator)1 SMTestProxy (com.intellij.execution.testframework.sm.runner.SMTestProxy)1