@@ -75,6 +75,8 @@ 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.lang.JavaVersion
79+ import com.intellij.util.ui.JBUI
7880import com.intellij.util.ui.JBUI.size
7981import com.intellij.util.ui.JBUI
8082import com.intellij.util.ui.UIUtil
@@ -221,6 +223,13 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
221223 contextHelpLabel?.let { add(it, BorderLayout .LINE_END ) }
222224 })
223225
226+ private fun findSdkVersion (): Int {
227+ val projectSdk = ModuleRootManager .getInstance(model.testModule).sdk
228+ val sdkVersion = JavaVersion .tryParse(projectSdk?.versionString)
229+ ? : error(" No sdk found in ${model.testModule} " )
230+ return sdkVersion.feature
231+ }
232+
224233 private fun findTestPackageComboValue (): String {
225234 val packageNames = model.srcClasses.map { it.packageName }.distinct()
226235 return if (packageNames.size == 1 ) packageNames.first() else SAME_PACKAGE_LABEL
@@ -710,9 +719,9 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
710719
711720 parametrizedTestSources.addActionListener { event ->
712721 val comboBox = event.source as ComboBox <* >
713- val item = comboBox.item as ParametrizedTestSource
722+ val parametrizedTestSource = comboBox.item as ParametrizedTestSource
714723
715- val areMocksSupported = item == ParametrizedTestSource .DO_NOT_PARAMETRIZE
724+ val areMocksSupported = parametrizedTestSource == ParametrizedTestSource .DO_NOT_PARAMETRIZE
716725
717726 mockStrategies.isEnabled = areMocksSupported
718727 staticsMocking.isEnabled = areMocksSupported && mockStrategies.item != MockStrategyApi .NO_MOCKS
@@ -723,7 +732,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
723732 staticsMocking.item = NoStaticMocking
724733 }
725734
726- updateTestFrameworksList(item )
735+ updateTestFrameworksList(parametrizedTestSource )
727736 }
728737
729738 cbSpecifyTestPackage.addActionListener {
@@ -744,10 +753,17 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
744753 // We would like to remove JUnit4 from framework list in parametrized mode
745754 private fun updateTestFrameworksList (parametrizedTestSource : ParametrizedTestSource ) {
746755 // We do not support parameterized tests for JUnit4
747- val enabledTestFrameworks = when (parametrizedTestSource) {
756+ var enabledTestFrameworks = when (parametrizedTestSource) {
748757 ParametrizedTestSource .DO_NOT_PARAMETRIZE -> TestFramework .allItems
749758 ParametrizedTestSource .PARAMETRIZE -> TestFramework .allItems.filterNot { it == Junit4 }
750759 }
760+
761+ // Will be removed after gradle-intelij-plugin version update upper than 2020.2
762+ // TestNg will be reverted after https://github.com/UnitTestBot/UTBotJava/issues/309
763+ if (findSdkVersion() < 11 ) {
764+ enabledTestFrameworks = enabledTestFrameworks.filterNot { it == TestNg }
765+ }
766+
751767 var defaultItem = when (parametrizedTestSource) {
752768 ParametrizedTestSource .DO_NOT_PARAMETRIZE -> TestFramework .defaultItem
753769 ParametrizedTestSource .PARAMETRIZE -> TestFramework .parametrizedDefaultItem
0 commit comments