Skip to content

Commit 720c973

Browse files
Reorder components in Spring UI and correct their behavior #2215 (#2231)
1 parent 6bed9b5 commit 720c973

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,6 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
411411
}
412412

413413
if (model.projectType == ProjectType.Spring) {
414-
row("Tests type:") {
415-
cell(sprintTestType)
416-
contextHelp(
417-
"Unit tests do not initialize ApplicationContext <br>" +
418-
"and do not autowire beans, while integration tests do."
419-
)
420-
}
421414
row("Spring configuration:") {
422415
cell(springConfig)
423416
contextHelp(
@@ -427,14 +420,23 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
427420
"Mocks will be used when necessary."
428421
)
429422
}
423+
row("Tests type:") {
424+
cell(sprintTestType)
425+
contextHelp(
426+
"Unit tests do not initialize ApplicationContext <br>" +
427+
"and do not autowire beans, while integration tests do."
428+
)
429+
}.enabledIf(
430+
ComboBoxPredicate(springConfig) { isSpringConfigSelected() && !isXmlSpringConfigUsed() }
431+
)
430432
row("Active profile(s):") {
431433
cell(profileNames)
432434
contextHelp(
433435
"One or several comma-separated names.<br>" +
434436
"If all names are incorrect, default profile is used"
435437
)
436438
}.enabledIf(
437-
ComboBoxPredicate(springConfig) { springConfig.item != NO_SPRING_CONFIGURATION_OPTION }
439+
ComboBoxPredicate(springConfig) { isSpringConfigSelected() }
438440
)
439441
}
440442

@@ -445,7 +447,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
445447
"Otherwise, mock nothing. Mockito will be installed, if you don't have one."
446448
)
447449
}.enabledIf(ComboBoxPredicate(springConfig) {
448-
model.projectType != ProjectType.Spring || springConfig.item == NO_SPRING_CONFIGURATION_OPTION
450+
model.projectType != ProjectType.Spring || !isSpringConfigSelected()
449451
})
450452
row { cell(staticsMocking)}
451453
row {
@@ -694,7 +696,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
694696
else -> {
695697
val shortConfigName = springConfig.item.toString()
696698
//TODO: avoid this check on xml here, merge two helpers into one
697-
val fullConfigName = if (shortConfigName.endsWith(".xml")) {
699+
val fullConfigName = if (isXmlSpringConfigUsed()) {
698700
xmlConfigurationHelper.restoreFullName(shortConfigName)
699701
} else {
700702
javaConfigurationHelper.restoreFullName(shortConfigName)
@@ -827,6 +829,9 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
827829

828830
private fun trimPackageName(name: String?): String = name?.trim() ?: ""
829831

832+
private fun isSpringConfigSelected(): Boolean = springConfig.item != NO_SPRING_CONFIGURATION_OPTION
833+
private fun isXmlSpringConfigUsed(): Boolean = springConfig.item.toString().endsWith(".xml")
834+
830835
private fun initDefaultValues() {
831836
testPackageField.isEnabled = false
832837
cbSpecifyTestPackage.isEnabled = model.srcClasses.all { cl -> cl.packageName.isNotEmpty() }
@@ -852,7 +857,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
852857
?: if (settings.testFramework != Junit4) settings.testFramework else TestFramework.parametrizedDefaultItem
853858
}
854859

855-
sprintTestType.item = settings.springTestType
860+
sprintTestType.item = if (isSpringConfigSelected()) settings.springTestType else SpringTestType.defaultItem
856861

857862
updateTestFrameworksList(settings.parametrizedTestSource)
858863
updateParametrizationEnabled()
@@ -1135,12 +1140,12 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
11351140
}
11361141

11371142
springConfig.addActionListener { _ ->
1138-
val isSpringConfigSelected = springConfig.item != NO_SPRING_CONFIGURATION_OPTION
1139-
if (isSpringConfigSelected) {
1143+
if (isSpringConfigSelected()) {
11401144
mockStrategies.item = MockStrategyApi.springDefaultItem
11411145
mockStrategies.isEnabled = false
11421146
updateMockStrategyListForConfigGuidedTypeReplacements()
11431147

1148+
sprintTestType.isEnabled = !isXmlSpringConfigUsed()
11441149
profileNames.isEnabled = true
11451150
} else {
11461151
mockStrategies.item = when (model.projectType) {
@@ -1150,6 +1155,9 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
11501155
mockStrategies.isEnabled = true
11511156
updateMockStrategyList()
11521157

1158+
sprintTestType.isEnabled = false
1159+
sprintTestType.item = SpringTestType.defaultItem
1160+
11531161
profileNames.isEnabled = false
11541162
profileNames.text = ""
11551163
}

0 commit comments

Comments
 (0)