Files
openide/plugins/gradle/java/testSources/dsl/GradleWithGroovyTest.kt
Nikita Biriukov a4f688a137 [gradle][groovy] IDEA-257715 fulfill DECORATORS and rename it to PROJECT_CONTEXTS.
Rename to improve clarity: each element in this constant represents a method of Project class, providing a context of Project. It is used to run expressions in tests in different variations of Closure where Project is a delegate.

Also, add some more methods of Project providing such context.

GitOrigin-RevId: 290ce09e88bff7171e67b3be2abcb8f2c9f3df6d
2024-04-03 15:38:36 +00:00

72 lines
3.5 KiB
Kotlin

// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.gradle.dsl
import com.intellij.psi.PsiMethod
import com.intellij.testFramework.UsefulTestCase.assertOneElement
import com.intellij.testFramework.assertInstanceOf
import org.gradle.util.GradleVersion
import org.jetbrains.plugins.gradle.service.resolve.GradleCommonClassNames.GRADLE_API_DOMAIN_OBJECT_COLLECTION
import org.jetbrains.plugins.gradle.service.resolve.GradleCommonClassNames.GRADLE_API_PROJECT
import org.jetbrains.plugins.gradle.testFramework.GradleCodeInsightTestCase
import org.jetbrains.plugins.gradle.testFramework.annotations.AllGradleVersionsSource
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.GROOVY_LANG_CLOSURE
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.params.ParameterizedTest
class GradleWithGroovyTest : GradleCodeInsightTestCase() {
@ParameterizedTest
@AllGradleVersionsSource("$PROJECT_CONTEXTS, buildscript")
fun `test Project#allprojects call`(gradleVersion: GradleVersion, decorator: String) {
testGroovyProject(gradleVersion) {
@Suppress("SpellCheckingInspection")
testBuildscript(decorator, "<caret>allprojects {}") {
val call = elementUnderCaret(GrMethodCall::class.java)
val element = assertOneElement(call.multiResolve(false)).element
val method = assertInstanceOf<PsiMethod>(element)
assertEquals(GRADLE_API_PROJECT, method.containingClass!!.qualifiedName)
assertTrue(method.parameterList.parameters.first().type.equalsToText(GROOVY_LANG_CLOSURE))
}
}
}
@ParameterizedTest
@AllGradleVersionsSource("$PROJECT_CONTEXTS, buildscript")
fun `test DomainObjectCollection#all call`(gradleVersion: GradleVersion, decorator: String) {
testGroovyProject(gradleVersion) {
testBuildscript(decorator, "<caret>configurations.all {}") {
val call = elementUnderCaret(GrMethodCall::class.java)
val element = assertOneElement(call.multiResolve(false)).element
val method = assertInstanceOf<PsiMethod>(element)
assertEquals(GRADLE_API_DOMAIN_OBJECT_COLLECTION, method.containingClass!!.qualifiedName)
assertTrue(method.parameterList.parameters.first().type.equalsToText(GROOVY_LANG_CLOSURE))
}
}
}
@ParameterizedTest
@AllGradleVersionsSource("$PROJECT_CONTEXTS, buildscript")
fun `test DomainObjectCollection#withType call`(gradleVersion: GradleVersion, decorator: String) {
testGroovyProject(gradleVersion) {
testBuildscript(decorator, "<caret>plugins.withType(JavaPlugin) {}") {
val call = elementUnderCaret(GrMethodCall::class.java)
val element = assertOneElement(call.multiResolve(false)).element
val method = assertInstanceOf<PsiMethod>(element)
assertEquals(GRADLE_API_DOMAIN_OBJECT_COLLECTION, method.containingClass!!.qualifiedName)
assertTrue(method.parameterList.parameters.last().type.equalsToText(GROOVY_LANG_CLOSURE))
}
}
}
@ParameterizedTest
@AllGradleVersionsSource
fun `test DGM#collect`(gradleVersion: GradleVersion) {
testGroovyProject(gradleVersion) {
codeInsightFixture.enableInspections(GroovyAssignabilityCheckInspection::class.java)
testHighlighting("['a', 'b'].collect { it.toUpperCase() }")
}
}
}