Skip to content

Commit 3782ce5

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

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
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: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,7 @@ import org.utbot.framework.plugin.api.MockFramework.MOCKITO
116116
import org.utbot.framework.plugin.api.MockStrategyApi
117117
import org.utbot.framework.plugin.api.TreatOverflowAsError
118118
import org.utbot.framework.util.Conflict
119-
import org.utbot.intellij.plugin.models.GenerateTestsModel
120-
import org.utbot.intellij.plugin.models.id
121-
import org.utbot.intellij.plugin.models.jUnit4LibraryDescriptor
122-
import org.utbot.intellij.plugin.models.jUnit5LibraryDescriptor
123-
import org.utbot.intellij.plugin.models.jUnit5ParametrizedTestsLibraryDescriptor
124-
import org.utbot.intellij.plugin.models.mockitoCoreLibraryDescriptor
125-
import org.utbot.intellij.plugin.models.packageName
126-
import org.utbot.intellij.plugin.models.testNgLibraryDescriptor
119+
import org.utbot.intellij.plugin.models.*
127120
import org.utbot.intellij.plugin.settings.Settings
128121
import org.utbot.intellij.plugin.ui.components.CodeGenerationSettingItemRenderer
129122
import org.utbot.intellij.plugin.ui.components.TestFolderComboWithBrowseButton
@@ -314,15 +307,16 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
314307
label?.let { add(it, BorderLayout.LINE_END) }
315308
})
316309

317-
private fun findSdkVersion(): JavaVersion? {
318-
val projectSdk = ModuleRootManager.getInstance(model.srcModule).sdk
319-
return JavaVersion.tryParse(projectSdk?.versionString)
310+
private fun findSdkVersion(): JavaVersion {
311+
val moduleSdk = ModuleRootManager.getInstance(model.srcModule).sdk
312+
return JavaVersion.tryParse(moduleSdk?.versionString)
313+
?: error("Cannot define sdk version in module ${model.srcModule}")
320314
}
321315

322316
override fun createTitlePane(): JComponent? {
323317
val sdkVersion = findSdkVersion()
324318
//TODO:SAT-1571 investigate Android Studio specific sdk issues
325-
if (sdkVersion?.feature in minSupportedSdkVersion..maxSupportedSdkVersion || IntelliJApiHelper.isAndroidStudio()) return null
319+
if (sdkVersion.feature in minSupportedSdkVersion..maxSupportedSdkVersion || IntelliJApiHelper.isAndroidStudio()) return null
326320
isOKActionEnabled = false
327321
return SdkNotificationPanel(model, sdkVersion)
328322
}
@@ -373,7 +367,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
373367
{ projectStructure.select(model.srcModule.name, ClasspathEditor.getName(), true) }
374368

375369
val sdkVersion = findSdkVersion()
376-
val sdkFixed = isEdited && sdkVersion?.feature in minSupportedSdkVersion..maxSupportedSdkVersion
370+
val sdkFixed = isEdited && sdkVersion.feature in minSupportedSdkVersion..maxSupportedSdkVersion
377371
if (sdkFixed) {
378372
this@SdkNotificationPanel.isVisible = false
379373
isOKActionEnabled = true
@@ -721,11 +715,15 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
721715
val libraryInProject =
722716
findFrameworkLibrary(model.project, model.testModule, selectedTestFramework, LibrarySearchScope.Project)
723717
val versionInProject = libraryInProject?.libraryName?.parseVersion()
718+
val sdkVersion: Int? = findSdkVersion().feature
724719

725720
val libraryDescriptor = when (selectedTestFramework) {
726721
Junit4 -> jUnit4LibraryDescriptor(versionInProject)
727722
Junit5 -> jUnit5LibraryDescriptor(versionInProject)
728-
TestNg -> testNgLibraryDescriptor(versionInProject)
723+
TestNg -> when (sdkVersion) {
724+
minSupportedSdkVersion -> testNgOldLibraryDescriptor()
725+
else -> testNgNewLibraryDescriptor(versionInProject)
726+
}
729727
}
730728

731729
selectedTestFramework.isInstalled = true

0 commit comments

Comments
 (0)