mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IJ-CR-129986 [Gradle|TestFramework] fix: restore application and project initial state after each Gradle code insight test
GitOrigin-RevId: b2d59521f4aeec4ce6aa48f312377861fefb57d2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
31884a4053
commit
ac748035e8
+41
-12
@@ -1,30 +1,59 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.gradle.testFramework
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.testFramework.common.runAll
|
||||
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleCodeInsightTestFixture
|
||||
import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleTestFixtureFactory
|
||||
import com.intellij.testFramework.fixtures.impl.JavaCodeInsightTestFixtureImpl
|
||||
import com.intellij.testFramework.fixtures.impl.TempDirTestFixtureImpl
|
||||
import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleProjectTestFixture
|
||||
import org.jetbrains.plugins.groovy.util.BaseTest
|
||||
|
||||
abstract class GradleCodeInsightBaseTestCase : GradleProjectTestCase(), BaseTest {
|
||||
|
||||
private var _codeInsightFixture: JavaCodeInsightTestFixture? = null
|
||||
val codeInsightFixture: JavaCodeInsightTestFixture
|
||||
get() = (gradleFixture as GradleCodeInsightTestFixture).codeInsightFixture
|
||||
get() = requireNotNull(_codeInsightFixture) {
|
||||
"Gradle code insight fixture wasn't setup. Please use [GradleBaseTestCase.test] function inside your tests."
|
||||
}
|
||||
|
||||
override fun getFixture(): JavaCodeInsightTestFixture = codeInsightFixture
|
||||
|
||||
override fun patchFixtureBuilder(fixtureBuilder: GradleTestFixtureBuilder): GradleTestFixtureBuilder =
|
||||
GradleCodeInsightTestFixtureBuilder(fixtureBuilder)
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
|
||||
private class GradleCodeInsightTestFixtureBuilder(private val builder: GradleTestFixtureBuilder) : GradleTestFixtureBuilder {
|
||||
_codeInsightFixture = GradleCodeInsightTestFixture(gradleFixture)
|
||||
codeInsightFixture.setUp()
|
||||
}
|
||||
|
||||
override val projectName: String by builder::projectName
|
||||
override fun tearDown() {
|
||||
runAll(
|
||||
{ _codeInsightFixture?.tearDown() },
|
||||
{ _codeInsightFixture = null },
|
||||
{ super.tearDown() }
|
||||
)
|
||||
}
|
||||
|
||||
override fun createFixture(gradleVersion: GradleVersion): GradleCodeInsightTestFixture {
|
||||
val gradleFixture = builder.createFixture(gradleVersion)
|
||||
val fixtureFactory = GradleTestFixtureFactory.getFixtureFactory()
|
||||
return fixtureFactory.createGradleCodeInsightTestFixture(gradleFixture)
|
||||
private class GradleIdeaProjectTestFixture(private val gradleFixture: GradleProjectTestFixture) : IdeaProjectTestFixture {
|
||||
override fun getProject(): Project = gradleFixture.project
|
||||
override fun getModule(): Module = gradleFixture.module
|
||||
override fun setUp() = Unit
|
||||
override fun tearDown() = Unit
|
||||
}
|
||||
|
||||
private class GradleCodeInsightTestFixture(
|
||||
gradleFixture: GradleProjectTestFixture
|
||||
) : JavaCodeInsightTestFixtureImpl(
|
||||
GradleIdeaProjectTestFixture(gradleFixture),
|
||||
TempDirTestFixtureImpl()
|
||||
) {
|
||||
|
||||
override fun shouldTrackVirtualFilePointers(): Boolean = false
|
||||
|
||||
init {
|
||||
setVirtualFileFilter(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-10
@@ -30,16 +30,6 @@ interface GradleTestFixtureFactory {
|
||||
configure: FileTestFixture.Builder.() -> Unit
|
||||
): GradleProjectTestFixture
|
||||
|
||||
fun createGradleCodeInsightTestFixture(
|
||||
projectName: String,
|
||||
gradleVersion: GradleVersion,
|
||||
configure: FileTestFixture.Builder.() -> Unit
|
||||
): GradleCodeInsightTestFixture
|
||||
|
||||
fun createGradleCodeInsightTestFixture(
|
||||
gradleProjectTestFixture: GradleProjectTestFixture
|
||||
): GradleCodeInsightTestFixture
|
||||
|
||||
companion object {
|
||||
private val ourInstance = GradleTestFixtureFactoryImpl()
|
||||
|
||||
|
||||
-51
@@ -1,51 +0,0 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.plugins.gradle.testFramework.fixtures.impl
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.testFramework.common.runAll
|
||||
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
|
||||
import com.intellij.testFramework.fixtures.impl.JavaCodeInsightTestFixtureImpl
|
||||
import com.intellij.testFramework.fixtures.impl.TempDirTestFixtureImpl
|
||||
import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleCodeInsightTestFixture
|
||||
import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleProjectTestFixture
|
||||
|
||||
class GradleCodeInsightTestFixtureImpl private constructor(
|
||||
private val gradleFixture: GradleProjectTestFixture,
|
||||
override val codeInsightFixture: JavaCodeInsightTestFixture
|
||||
) : GradleCodeInsightTestFixture, GradleProjectTestFixture by gradleFixture {
|
||||
|
||||
constructor(fixture: GradleProjectTestFixture) : this(fixture, createCodeInsightFixture(fixture))
|
||||
|
||||
override fun setUp() {
|
||||
gradleFixture.setUp()
|
||||
codeInsightFixture.setUp()
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
runAll(
|
||||
{ codeInsightFixture.tearDown() },
|
||||
{ gradleFixture.tearDown() }
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun createCodeInsightFixture(gradleFixture: GradleProjectTestFixture): JavaCodeInsightTestFixture {
|
||||
val tempDirFixture = TempDirTestFixtureImpl()
|
||||
val projectFixture = object : IdeaProjectTestFixture {
|
||||
override fun getProject(): Project = gradleFixture.project
|
||||
override fun getModule(): Module = gradleFixture.module
|
||||
override fun setUp() = Unit
|
||||
override fun tearDown() = Unit
|
||||
}
|
||||
return object : JavaCodeInsightTestFixtureImpl(projectFixture, tempDirFixture) {
|
||||
override fun shouldTrackVirtualFilePointers(): Boolean = false
|
||||
|
||||
init {
|
||||
setVirtualFileFilter(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-14
@@ -35,18 +35,4 @@ internal class GradleTestFixtureFactoryImpl : GradleTestFixtureFactory {
|
||||
): GradleProjectTestFixture {
|
||||
return GradleProjectTestFixtureImpl(projectName, gradleVersion, configure)
|
||||
}
|
||||
|
||||
override fun createGradleCodeInsightTestFixture(
|
||||
projectName: String,
|
||||
gradleVersion: GradleVersion,
|
||||
configure: FileTestFixture.Builder.() -> Unit
|
||||
): GradleCodeInsightTestFixture {
|
||||
return createGradleCodeInsightTestFixture(
|
||||
createGradleProjectTestFixture(projectName, gradleVersion, configure)
|
||||
)
|
||||
}
|
||||
|
||||
override fun createGradleCodeInsightTestFixture(gradleProjectTestFixture: GradleProjectTestFixture): GradleCodeInsightTestFixture {
|
||||
return GradleCodeInsightTestFixtureImpl(gradleProjectTestFixture)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user