Skip to content

Commit 74a0623

Browse files
committed
Different versions of TestNg can be installed into project
1 parent c91f383 commit 74a0623

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/ExternalLibraryDescriptors.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ val ExternalLibraryDescriptor.mavenCoordinates: String
77
get() = "$libraryGroupId:$libraryArtifactId:${preferredVersion ?: RepositoryLibraryDescription.ReleaseVersionId}"
88

99
val ExternalLibraryDescriptor.id: String
10-
get() = "$libraryGroupId:$libraryArtifactId"
10+
get() = "$libraryGroupId:$libraryArtifactId"
1111

1212
//TODO: think about using JUnitExternalLibraryDescriptor from intellij-community sources (difficult to install)
1313
fun jUnit4LibraryDescriptor(versionInProject: String?) =
@@ -16,11 +16,20 @@ fun jUnit4LibraryDescriptor(versionInProject: String?) =
1616
fun jUnit5LibraryDescriptor(versionInProject: String?) =
1717
ExternalLibraryDescriptor("org.junit.jupiter", "junit-jupiter", "5.8.1", null, versionInProject ?: "5.8.1")
1818

19-
fun testNgLibraryDescriptor(versionInProject: String?) =
20-
ExternalLibraryDescriptor("org.testng", "testng", "7.6.0", null, versionInProject ?: "7.6.0")
21-
2219
fun jUnit5ParametrizedTestsLibraryDescriptor(versionInProject: String?) =
2320
ExternalLibraryDescriptor("org.junit.jupiter", "junit-jupiter-params", "5.8.1", null, versionInProject ?: "5.8.1")
2421

2522
fun mockitoCoreLibraryDescriptor(versionInProject: String?) =
26-
ExternalLibraryDescriptor("org.mockito", "mockito-core", "3.5.0", "4.2.0", versionInProject ?: "4.2.0")
23+
ExternalLibraryDescriptor("org.mockito", "mockito-core", "3.5.0", "4.2.0", versionInProject ?: "4.2.0")
24+
25+
/**
26+
* TestNg requires JDK 11 since version 7.6.0
27+
* For projects with JDK 8 version 7.5.0 should be installed.
28+
* See https://groups.google.com/g/testng-users/c/BAFB1vk-kok?pli=1 for more details.
29+
*/
30+
31+
fun testNgNewLibraryDescriptor(versionInProject: String?) =
32+
ExternalLibraryDescriptor("org.testng", "testng", "7.6.0", null, versionInProject ?: "7.6.0")
33+
34+
fun testNgOldLibraryDescriptor() =
35+
ExternalLibraryDescriptor("org.testng", "testng", "7.5.0", null, "7.5.0")

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ import org.utbot.intellij.plugin.models.jUnit5LibraryDescriptor
123123
import org.utbot.intellij.plugin.models.jUnit5ParametrizedTestsLibraryDescriptor
124124
import org.utbot.intellij.plugin.models.mockitoCoreLibraryDescriptor
125125
import org.utbot.intellij.plugin.models.packageName
126-
import org.utbot.intellij.plugin.models.testNgLibraryDescriptor
126+
import org.utbot.intellij.plugin.models.testNgNewLibraryDescriptor
127+
import org.utbot.intellij.plugin.models.testNgOldLibraryDescriptor
127128
import org.utbot.intellij.plugin.settings.Settings
128129
import org.utbot.intellij.plugin.ui.components.CodeGenerationSettingItemRenderer
129130
import org.utbot.intellij.plugin.ui.components.TestFolderComboWithBrowseButton
@@ -314,15 +315,16 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
314315
label?.let { add(it, BorderLayout.LINE_END) }
315316
})
316317

317-
private fun findSdkVersion(): JavaVersion? {
318-
val projectSdk = ModuleRootManager.getInstance(model.srcModule).sdk
319-
return JavaVersion.tryParse(projectSdk?.versionString)
318+
private fun findSdkVersion(): JavaVersion {
319+
val moduleSdk = ModuleRootManager.getInstance(model.srcModule).sdk
320+
return JavaVersion.tryParse(moduleSdk?.versionString)
321+
?: error("Cannot define sdk version in module ${model.srcModule}")
320322
}
321323

322324
override fun createTitlePane(): JComponent? {
323325
val sdkVersion = findSdkVersion()
324326
//TODO:SAT-1571 investigate Android Studio specific sdk issues
325-
if (sdkVersion?.feature in minSupportedSdkVersion..maxSupportedSdkVersion || IntelliJApiHelper.isAndroidStudio()) return null
327+
if (sdkVersion.feature in minSupportedSdkVersion..maxSupportedSdkVersion || IntelliJApiHelper.isAndroidStudio()) return null
326328
isOKActionEnabled = false
327329
return SdkNotificationPanel(model, sdkVersion)
328330
}
@@ -373,7 +375,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
373375
{ projectStructure.select(model.srcModule.name, ClasspathEditor.getName(), true) }
374376

375377
val sdkVersion = findSdkVersion()
376-
val sdkFixed = isEdited && sdkVersion?.feature in minSupportedSdkVersion..maxSupportedSdkVersion
378+
val sdkFixed = isEdited && sdkVersion.feature in minSupportedSdkVersion..maxSupportedSdkVersion
377379
if (sdkFixed) {
378380
this@SdkNotificationPanel.isVisible = false
379381
isOKActionEnabled = true
@@ -721,11 +723,15 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
721723
val libraryInProject =
722724
findFrameworkLibrary(model.project, model.testModule, selectedTestFramework, LibrarySearchScope.Project)
723725
val versionInProject = libraryInProject?.libraryName?.parseVersion()
726+
val sdkVersion: Int? = findSdkVersion().feature
724727

725728
val libraryDescriptor = when (selectedTestFramework) {
726729
Junit4 -> jUnit4LibraryDescriptor(versionInProject)
727730
Junit5 -> jUnit5LibraryDescriptor(versionInProject)
728-
TestNg -> testNgLibraryDescriptor(versionInProject)
731+
TestNg -> when (sdkVersion) {
732+
minSupportedSdkVersion -> testNgOldLibraryDescriptor()
733+
else -> testNgNewLibraryDescriptor(versionInProject)
734+
}
729735
}
730736

731737
selectedTestFramework.isInstalled = true
@@ -956,12 +962,6 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
956962
ParametrizedTestSource.PARAMETRIZE -> TestFramework.allItems.filterNot { it == Junit4 }
957963
}
958964

959-
//Will be removed after gradle-intelij-plugin version update upper than 2020.2
960-
//TestNg will be reverted after https://github.com/UnitTestBot/UTBotJava/issues/309
961-
if (findSdkVersion()?.let { it.feature < 11 } == true) {
962-
enabledTestFrameworks = enabledTestFrameworks.filterNot { it == TestNg }
963-
}
964-
965965
var defaultItem = when (parametrizedTestSource) {
966966
ParametrizedTestSource.DO_NOT_PARAMETRIZE -> TestFramework.defaultItem
967967
ParametrizedTestSource.PARAMETRIZE -> TestFramework.parametrizedDefaultItem

0 commit comments

Comments
 (0)