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