@@ -75,8 +75,9 @@ import com.intellij.ui.layout.Row
7575import com.intellij.ui.layout.panel
7676import com.intellij.util.IncorrectOperationException
7777import com.intellij.util.io.exists
78- import com.intellij.util.ui.JBUI.size
78+ import com.intellij.util.lang.JavaVersion
7979import com.intellij.util.ui.JBUI
80+ import com.intellij.util.ui.JBUI.size
8081import com.intellij.util.ui.UIUtil
8182import java.awt.BorderLayout
8283import java.nio.file.Files
@@ -221,6 +222,13 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
221222 contextHelpLabel?.let { add(it, BorderLayout .LINE_END ) }
222223 })
223224
225+ private fun findSdkVersion (): Int {
226+ val projectSdk = ModuleRootManager .getInstance(model.testModule).sdk
227+ val sdkVersion = JavaVersion .tryParse(projectSdk?.versionString)
228+ ? : error(" No sdk found in ${model.testModule} " )
229+ return sdkVersion.feature
230+ }
231+
224232 private fun findTestPackageComboValue (): String {
225233 val packageNames = model.srcClasses.map { it.packageName }.distinct()
226234 return if (packageNames.size == 1 ) packageNames.first() else SAME_PACKAGE_LABEL
@@ -710,9 +718,9 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
710718
711719 parametrizedTestSources.addActionListener { event ->
712720 val comboBox = event.source as ComboBox <* >
713- val item = comboBox.item as ParametrizedTestSource
721+ val parametrizedTestSource = comboBox.item as ParametrizedTestSource
714722
715- val areMocksSupported = item == ParametrizedTestSource .DO_NOT_PARAMETRIZE
723+ val areMocksSupported = parametrizedTestSource == ParametrizedTestSource .DO_NOT_PARAMETRIZE
716724
717725 mockStrategies.isEnabled = areMocksSupported
718726 staticsMocking.isEnabled = areMocksSupported && mockStrategies.item != MockStrategyApi .NO_MOCKS
@@ -723,7 +731,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
723731 staticsMocking.item = NoStaticMocking
724732 }
725733
726- updateTestFrameworksList(item )
734+ updateTestFrameworksList(parametrizedTestSource )
727735 }
728736
729737 cbSpecifyTestPackage.addActionListener {
@@ -744,10 +752,17 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
744752 // We would like to remove JUnit4 from framework list in parametrized mode
745753 private fun updateTestFrameworksList (parametrizedTestSource : ParametrizedTestSource ) {
746754 // We do not support parameterized tests for JUnit4
747- val enabledTestFrameworks = when (parametrizedTestSource) {
755+ var enabledTestFrameworks = when (parametrizedTestSource) {
748756 ParametrizedTestSource .DO_NOT_PARAMETRIZE -> TestFramework .allItems
749757 ParametrizedTestSource .PARAMETRIZE -> TestFramework .allItems.filterNot { it == Junit4 }
750758 }
759+
760+ // Will be removed after gradle-intelij-plugin version update upper than 2020.2
761+ // TestNg will be reverted after https://github.com/UnitTestBot/UTBotJava/issues/309
762+ if (findSdkVersion() < 11 ) {
763+ enabledTestFrameworks = enabledTestFrameworks.filterNot { it == TestNg }
764+ }
765+
751766 var defaultItem = when (parametrizedTestSource) {
752767 ParametrizedTestSource .DO_NOT_PARAMETRIZE -> TestFramework .defaultItem
753768 ParametrizedTestSource .PARAMETRIZE -> TestFramework .parametrizedDefaultItem
0 commit comments