IDEA-CR-44255 added tests

This commit is contained in:
Sergei Vorobyov
2019-03-04 16:09:19 +03:00
committed by Sergei Vorobyov
parent dfca52f936
commit d8fd2f17a1
2 changed files with 35 additions and 2 deletions
@@ -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<PatternGradleConfigurationProducer>()
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)))
}
}
}
}
@@ -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