[kotlin] Make 'TestNgKotlinTestFrameworkProvider' a class (KTIJ-24476)

Extensions are instantiated by the platform, breaking the objects' singleton contract.

GitOrigin-RevId: c606bfc71bc8fa7086663a7023503ce0cc3da6f6
This commit is contained in:
Yan Zhulanow
2023-02-14 17:30:12 +09:00
committed by intellij-monorepo-bot
parent 4103031a17
commit 77c55a7e7f
2 changed files with 16 additions and 4 deletions

View File

@@ -41,7 +41,7 @@ public class KotlinTestNgConfigurationProducer extends TestNGConfigurationProduc
@NotNull TestNGConfiguration configuration,
@NotNull ConfigurationContext context, @NotNull PsiElement element
) {
KotlinTestFrameworkProvider.JavaEntity javaEntity = TestNgKotlinTestFrameworkProvider.INSTANCE.getJavaEntity(element);
KotlinTestFrameworkProvider.JavaEntity javaEntity = TestNgKotlinTestFrameworkProvider.getInstance().getJavaEntity(element);
if (javaEntity == null || !hasDetectedTestFramework(javaEntity.getTestClass())) {
return false;
}
@@ -75,7 +75,7 @@ public class KotlinTestNgConfigurationProducer extends TestNGConfigurationProduc
return false;
}
JavaTestEntity testEntity = TestNgKotlinTestFrameworkProvider.INSTANCE.getJavaTestEntity(leaf, true);
JavaTestEntity testEntity = TestNgKotlinTestFrameworkProvider.getInstance().getJavaTestEntity(leaf, true);
if (testEntity == null) {
return false;
}
@@ -85,7 +85,9 @@ public class KotlinTestNgConfigurationProducer extends TestNGConfigurationProduc
@Override
public void onFirstRun(ConfigurationFromContext configuration, @NotNull ConfigurationContext context, @NotNull Runnable startRunnable) {
JavaTestEntity testEntity = TestNgKotlinTestFrameworkProvider.INSTANCE.getJavaTestEntity(configuration.getSourceElement(), true);
JavaTestEntity testEntity = TestNgKotlinTestFrameworkProvider.getInstance()
.getJavaTestEntity(configuration.getSourceElement(), true);
if (testEntity == null) {
super.onFirstRun(configuration, context, startRunnable);
return;

View File

@@ -10,11 +10,21 @@ import com.intellij.psi.PsiMethod
import com.intellij.psi.util.PsiClassUtil
import com.theoryinpractice.testng.configuration.TestNGConfigurationProducer
import com.theoryinpractice.testng.util.TestNGUtil
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.kotlin.idea.base.codeInsight.FrameworkAvailabilityChecker
import org.jetbrains.kotlin.idea.base.codeInsight.isFrameworkAvailable
import org.jetbrains.kotlin.idea.extensions.KotlinTestFrameworkProvider
object TestNgKotlinTestFrameworkProvider : KotlinTestFrameworkProvider {
@ApiStatus.Internal
class TestNgKotlinTestFrameworkProvider : KotlinTestFrameworkProvider {
companion object {
@JvmStatic
fun getInstance(): TestNgKotlinTestFrameworkProvider {
return KotlinTestFrameworkProvider.EP_NAME
.findExtensionOrFail(TestNgKotlinTestFrameworkProvider::class.java)
}
}
override val canRunJvmTests: Boolean
get() = true