From d8fd2f17a15f74139905e59fafc2f84dbab85df5 Mon Sep 17 00:00:00 2001 From: Sergei Vorobyov Date: Fri, 1 Mar 2019 19:52:09 +0300 Subject: [PATCH] IDEA-CR-44255 added tests --- .../GradleTestRunConfigurationProducerTest.kt | 25 +++++++++++++++++++ ...dleTestRunConfigurationProducerTestCase.kt | 12 +++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/plugins/gradle/java/testSources/execution/test/runner/GradleTestRunConfigurationProducerTest.kt b/plugins/gradle/java/testSources/execution/test/runner/GradleTestRunConfigurationProducerTest.kt index 7b78235edc70..9ae32bcc3075 100644 --- a/plugins/gradle/java/testSources/execution/test/runner/GradleTestRunConfigurationProducerTest.kt +++ b/plugins/gradle/java/testSources/execution/test/runner/GradleTestRunConfigurationProducerTest.kt @@ -2,6 +2,7 @@ package org.jetbrains.plugins.gradle.execution.test.runner import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration +import com.intellij.openapi.util.Ref import com.intellij.psi.PsiClass import com.intellij.psi.PsiDirectory import com.intellij.psi.PsiMethod @@ -159,4 +160,28 @@ class GradleTestRunConfigurationProducerTest : GradleTestRunConfigurationProduce projectData["module"].root ) } + + @Test + fun `test multiple selected abstract tests`() { + val projectData = generateAndImportTemplateProject() + runReadActionAndWait { + val producer = getConfigurationProducer() + val testClass = projectData["project"]["TestCase"].element + val abstractTestClass = projectData["project"]["AbstractTestCase"].element + val abstractTestMethod = projectData["project"]["AbstractTestCase"]["test"].element + val templateConfiguration = producer.createTemplateConfiguration() + getContextByLocation(testClass, abstractTestClass).let { + assertTrue(producer.setupConfigurationFromContext(templateConfiguration, it, Ref(it.psiLocation))) + } + getContextByLocation(abstractTestClass, abstractTestMethod).let { + assertFalse(producer.setupConfigurationFromContext(templateConfiguration, it, Ref(it.psiLocation))) + } + getContextByLocation(abstractTestClass, abstractTestClass).let { + assertFalse(producer.setupConfigurationFromContext(templateConfiguration, it, Ref(it.psiLocation))) + } + getContextByLocation(abstractTestMethod, abstractTestMethod).let { + assertFalse(producer.setupConfigurationFromContext(templateConfiguration, it, Ref(it.psiLocation))) + } + } + } } diff --git a/plugins/gradle/java/testSources/execution/test/runner/GradleTestRunConfigurationProducerTestCase.kt b/plugins/gradle/java/testSources/execution/test/runner/GradleTestRunConfigurationProducerTestCase.kt index 1beaa9b7338b..07a8217d958a 100644 --- a/plugins/gradle/java/testSources/execution/test/runner/GradleTestRunConfigurationProducerTestCase.kt +++ b/plugins/gradle/java/testSources/execution/test/runner/GradleTestRunConfigurationProducerTestCase.kt @@ -31,7 +31,7 @@ abstract class GradleTestRunConfigurationProducerTestCase : GradleImportingTestC put(LangDataKeys.PROJECT, myProject) put(LangDataKeys.MODULE, ModuleUtilCore.findModuleForPsiElement(elements[0])) put(Location.DATA_KEY, PsiLocation.fromPsiElement(elements[0])) - put(Location.DATA_KEYS, elements.map { PsiLocation.fromPsiElement(it) }.toTypedArray()) + put(LangDataKeys.PSI_ELEMENT_ARRAY, elements) } return object : ConfigurationContext(elements[0]) { override fun getDataContext() = dataContext @@ -79,6 +79,10 @@ abstract class GradleTestRunConfigurationProducerTestCase : GradleImportingTestC } } + protected fun GradleTestRunConfigurationProducer.createTemplateConfiguration(): ExternalSystemRunConfiguration { + return configurationFactory.createTemplateConfiguration(myProject) as ExternalSystemRunConfiguration + } + protected fun generateAndImportTemplateProject(): ProjectData { val testCaseFile = createProjectSubFile("src/test/java/TestCase.java", """ import org.junit.Test; @@ -107,7 +111,7 @@ abstract class GradleTestRunConfigurationProducerTestCase : GradleImportingTestC """.trimIndent()) val abstractTestCaseFile = createProjectSubFile("src/test/java/AbstractTestCase.java", """ import org.junit.Test; - public class AbstractTestCase { + public abstract class AbstractTestCase { @Test public void test() {} } """.trimIndent()) @@ -138,9 +142,13 @@ abstract class GradleTestRunConfigurationProducerTestCase : GradleImportingTestC """.trimIndent()) val buildScript = GradleBuildScriptBuilderEx() .withJavaPlugin() + .withIdeaPlugin() .withJUnit("4.12") .withGroovyPlugin("2.4.14") .addPrefix(""" + idea.module { + testSourceDirs += file('automation') + } sourceSets { automation.java.srcDirs = ['automation'] automation.compileClasspath += sourceSets.test.runtimeClasspath