IJ-CR-129986 [Gradle|TestFramework] cleanup: renamed the GradleTestApplication to the GradleProjectTestApplication

Added the detailed comment for the GradleProjectTestApplication annotation. This annotation should be used only with the GradleProjectBaseTestCase

GitOrigin-RevId: 37f090b9a9d875964114739f2c5905610d215d02
This commit is contained in:
Sergei Vorobyov
2024-03-29 14:21:13 +00:00
committed by intellij-monorepo-bot
parent c22123f6b0
commit dd5043893a
4 changed files with 34 additions and 48 deletions
@@ -4,11 +4,11 @@ package org.jetbrains.plugins.gradle.testFramework
import com.intellij.testFramework.common.runAll
import org.gradle.util.GradleVersion
import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleProjectTestFixture
import org.jetbrains.plugins.gradle.testFramework.fixtures.application.GradleTestApplication
import org.jetbrains.plugins.gradle.testFramework.fixtures.application.GradleProjectTestApplication
import org.jetbrains.plugins.gradle.testFramework.util.onFailureCatching
import org.junit.jupiter.api.AfterAll
@GradleTestApplication
@GradleProjectTestApplication
abstract class GradleProjectBaseTestCase {
private var fixture: GradleProjectTestFixture? = null
@@ -1,22 +1,50 @@
// Copyright 2000-2024 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.application
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.invokeAndWaitIfNeeded
import com.intellij.openapi.roots.impl.libraries.LibraryTableTracker
import com.intellij.openapi.vfs.impl.VirtualFilePointerTracker
import com.intellij.testFramework.SdkLeakTracker
import com.intellij.testFramework.common.cleanApplicationState
import com.intellij.testFramework.common.runAll
import org.jetbrains.annotations.TestOnly
import com.intellij.testFramework.junit5.impl.testApplication
import org.jetbrains.plugins.gradle.testFramework.fixtures.tracker.ExternalSystemListenerLeakTracker
import org.junit.jupiter.api.extension.AfterAllCallback
import org.junit.jupiter.api.extension.BeforeAllCallback
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.api.extension.ExtensionContext
/**
* Custom application initializer for the [org.jetbrains.plugins.gradle.testFramework.GradleProjectBaseTestCase].
* This initializer has adjusted leak listeners to the [org.junit.jupiter.api.BeforeAll] and [org.junit.jupiter.api.AfterAll] bounds.
* It is necessary because [org.jetbrains.plugins.gradle.testFramework.GradleProjectBaseTestCase]
* orchestrate Gradle project with different configuration. These project instances are shared between tests.
* They can be closed and opened at any time between the tests.
*
* @see com.intellij.testFramework.junit5.TestApplication
*/
@Target(AnnotationTarget.CLASS)
@ExtendWith(
GradleProjectTestApplicationExtension::class,
GradleProjectTestApplicationLeakTrackerExtension::class,
)
annotation class GradleProjectTestApplication
private class GradleProjectTestApplicationExtension : BeforeAllCallback, AfterAllCallback {
override fun beforeAll(context: ExtensionContext) {
context.testApplication().getOrThrow()
}
override fun afterAll(context: ExtensionContext) {
ApplicationManager.getApplication().cleanApplicationState()
}
}
/**
* @see com.intellij.testFramework.junit5.impl.TestApplicationLeakTrackerExtension
*/
@TestOnly
class GradleTestApplicationLeakTrackerExtension : BeforeAllCallback, AfterAllCallback {
private class GradleProjectTestApplicationLeakTrackerExtension : BeforeAllCallback, AfterAllCallback {
companion object {
private const val LEAK_TRACKERS_KEY = "Gradle application-level leak trackers"
@@ -33,7 +61,6 @@ class GradleTestApplicationLeakTrackerExtension : BeforeAllCallback, AfterAllCal
.checkNothingLeaked()
}
@TestOnly
private class GradleLeakTrackers {
val sdkLeakTracker = SdkLeakTracker()
@@ -50,4 +77,4 @@ class GradleTestApplicationLeakTrackerExtension : BeforeAllCallback, AfterAllCal
)
}
}
}
}
@@ -1,17 +0,0 @@
// Copyright 2000-2024 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.application
import org.jetbrains.annotations.TestOnly
import org.junit.jupiter.api.extension.ExtendWith
/**
* @see com.intellij.testFramework.junit5.TestApplication
*/
@TestOnly
@Target(AnnotationTarget.CLASS)
@ExtendWith(
GradleTestApplicationExtension::class,
GradleTestApplicationLeakTrackerExtension::class,
)
annotation class GradleTestApplication {
}
@@ -1,24 +0,0 @@
// Copyright 2000-2024 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.application
import com.intellij.openapi.application.ApplicationManager
import com.intellij.testFramework.common.cleanApplicationState
import com.intellij.testFramework.junit5.impl.testApplication
import org.jetbrains.annotations.TestOnly
import org.junit.jupiter.api.extension.AfterAllCallback
import org.junit.jupiter.api.extension.BeforeAllCallback
import org.junit.jupiter.api.extension.ExtensionContext
/**
* @see com.intellij.testFramework.junit5.impl.TestApplicationExtension
*/
@TestOnly
class GradleTestApplicationExtension : BeforeAllCallback, AfterAllCallback {
override fun beforeAll(context: ExtensionContext) {
context.testApplication().getOrThrow()
}
override fun afterAll(context: ExtensionContext) {
ApplicationManager.getApplication().cleanApplicationState()
}
}