@@ -75,6 +75,8 @@ import com.intellij.ui.layout.Row
75
75
import com.intellij.ui.layout.panel
76
76
import com.intellij.util.IncorrectOperationException
77
77
import com.intellij.util.io.exists
78
+ import com.intellij.util.lang.JavaVersion
79
+ import com.intellij.util.ui.JBUI
78
80
import com.intellij.util.ui.JBUI.size
79
81
import com.intellij.util.ui.JBUI
80
82
import com.intellij.util.ui.UIUtil
@@ -221,6 +223,13 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
221
223
contextHelpLabel?.let { add(it, BorderLayout .LINE_END ) }
222
224
})
223
225
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
+
224
233
private fun findTestPackageComboValue (): String {
225
234
val packageNames = model.srcClasses.map { it.packageName }.distinct()
226
235
return if (packageNames.size == 1 ) packageNames.first() else SAME_PACKAGE_LABEL
@@ -710,9 +719,9 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
710
719
711
720
parametrizedTestSources.addActionListener { event ->
712
721
val comboBox = event.source as ComboBox <* >
713
- val item = comboBox.item as ParametrizedTestSource
722
+ val parametrizedTestSource = comboBox.item as ParametrizedTestSource
714
723
715
- val areMocksSupported = item == ParametrizedTestSource .DO_NOT_PARAMETRIZE
724
+ val areMocksSupported = parametrizedTestSource == ParametrizedTestSource .DO_NOT_PARAMETRIZE
716
725
717
726
mockStrategies.isEnabled = areMocksSupported
718
727
staticsMocking.isEnabled = areMocksSupported && mockStrategies.item != MockStrategyApi .NO_MOCKS
@@ -723,7 +732,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
723
732
staticsMocking.item = NoStaticMocking
724
733
}
725
734
726
- updateTestFrameworksList(item )
735
+ updateTestFrameworksList(parametrizedTestSource )
727
736
}
728
737
729
738
cbSpecifyTestPackage.addActionListener {
@@ -744,10 +753,17 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
744
753
// We would like to remove JUnit4 from framework list in parametrized mode
745
754
private fun updateTestFrameworksList (parametrizedTestSource : ParametrizedTestSource ) {
746
755
// We do not support parameterized tests for JUnit4
747
- val enabledTestFrameworks = when (parametrizedTestSource) {
756
+ var enabledTestFrameworks = when (parametrizedTestSource) {
748
757
ParametrizedTestSource .DO_NOT_PARAMETRIZE -> TestFramework .allItems
749
758
ParametrizedTestSource .PARAMETRIZE -> TestFramework .allItems.filterNot { it == Junit4 }
750
759
}
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
+
751
767
var defaultItem = when (parametrizedTestSource) {
752
768
ParametrizedTestSource .DO_NOT_PARAMETRIZE -> TestFramework .defaultItem
753
769
ParametrizedTestSource .PARAMETRIZE -> TestFramework .parametrizedDefaultItem
0 commit comments