@@ -99,9 +99,11 @@ import org.utbot.framework.plugin.api.CodegenLanguage
99
99
import org.utbot.framework.plugin.api.CodeGenerationSettingItem
100
100
import org.utbot.framework.plugin.api.SpringConfiguration
101
101
import org.utbot.framework.plugin.api.SpringTestType.*
102
+ import org.utbot.framework.plugin.api.SpringProfileNames
102
103
import org.utbot.framework.plugin.api.utils.MOCKITO_EXTENSIONS_FILE_CONTENT
103
104
import org.utbot.framework.plugin.api.utils.MOCKITO_EXTENSIONS_FOLDER
104
105
import org.utbot.framework.plugin.api.utils.MOCKITO_MOCKMAKER_FILE_NAME
106
+ import org.utbot.framework.plugin.api.NO_SPRING_CONFIGURATION_OPTION
105
107
import org.utbot.framework.util.Conflict
106
108
import org.utbot.intellij.plugin.models.GenerateTestsModel
107
109
import org.utbot.intellij.plugin.models.id
@@ -165,9 +167,6 @@ private const val SAME_PACKAGE_LABEL = "same as for sources"
165
167
166
168
private const val WILL_BE_INSTALLED_LABEL = " (will be installed)"
167
169
168
- private const val NO_SPRING_CONFIGURATION_OPTION = " No configuration"
169
- private const val DEFAULT_SPRING_PROFILE_NAME = " default"
170
-
171
170
private const val ACTION_GENERATE = " Generate Tests"
172
171
private const val ACTION_GENERATE_AND_RUN = " Generate and Run"
173
172
@@ -202,7 +201,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
202
201
203
202
private val springTestType = createComboBox(SpringTestType .values()).also { it.setMinimumAndPreferredWidth(300 ) }
204
203
private val springConfig = createComboBoxWithSeparatorsForSpringConfigs(shortenConfigurationNames())
205
- private val profileNames = JBTextField (23 ).apply { emptyText.text = DEFAULT_SPRING_PROFILE_NAME }
204
+ private val springProfileNames = JBTextField (23 ).apply { emptyText.text = SpringProfileNames .defaultItem }
206
205
207
206
private val timeoutSpinner =
208
207
JBIntSpinner (TimeUnit .MILLISECONDS .toSeconds(model.timeout).toInt(), 1 , Int .MAX_VALUE , 1 ).also {
@@ -245,6 +244,11 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
245
244
)
246
245
}
247
246
247
+ private fun shortenConfigurationNameByFullname (fullname : String ): String? {
248
+ val allShortenConfigurationNames = shortenConfigurationNames().flatMap { it.second }
249
+ return allShortenConfigurationNames.firstOrNull { fullname.endsWith(it) }
250
+ }
251
+
248
252
private fun <T : CodeGenerationSettingItem > createComboBox (values : Array <T >) : ComboBox <T > {
249
253
val comboBox = object : ComboBox <T >(DefaultComboBoxModel (values)) {
250
254
var maxWidth = 0
@@ -428,7 +432,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
428
432
ComboBoxPredicate (springConfig) { isSpringConfigSelected() && ! isXmlSpringConfigUsed() }
429
433
)
430
434
row(" Active profile(s):" ) {
431
- cell(profileNames )
435
+ cell(springProfileNames )
432
436
contextHelp(
433
437
" One or several comma-separated names.<br>" +
434
438
" If all names are incorrect, default profile is used"
@@ -736,12 +740,14 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
736
740
737
741
PresentSpringSettings (
738
742
configuration = config,
739
- profiles = parseProfileExpression(profileNames .text, DEFAULT_SPRING_PROFILE_NAME ).toList()
743
+ profiles = parseProfileExpression(springProfileNames .text, SpringProfileNames .defaultItem ).toList()
740
744
)
741
745
}
742
746
}
743
747
744
748
model.springTestType = springTestType.item
749
+ model.springConfig = springConfig.item.toString()
750
+ model.springProfileNames = springProfileNames.text
745
751
746
752
val settings = model.project.service<Settings >()
747
753
with (settings) {
@@ -883,21 +889,20 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
883
889
if (settings.fuzzingValue == 0.0 ) 0.0
884
890
else settings.fuzzingValue.coerceAtLeast(0.3 )
885
891
}
892
+ springConfig.item = settings.springConfig
886
893
}
887
894
else -> {}
888
895
}
889
896
890
897
mockStrategies.item = when (model.projectType) {
891
- ProjectType .Spring -> MockStrategyApi .springDefaultItem
898
+ ProjectType .Spring ->
899
+ if (isSpringConfigSelected()) MockStrategyApi .springDefaultItem else settings.mockStrategy
892
900
else -> settings.mockStrategy
893
901
}
894
902
staticsMocking.isSelected = settings.staticsMocking == MockitoStaticMocking
895
903
parametrizedTestSources.isSelected = (settings.parametrizedTestSource == ParametrizedTestSource .PARAMETRIZE
896
904
&& model.projectType == ProjectType .PureJvm )
897
905
898
- mockStrategies.isEnabled = true
899
- staticsMocking.isEnabled = mockStrategies.item != MockStrategyApi .NO_MOCKS
900
-
901
906
codegenLanguages.item = model.codegenLanguage
902
907
903
908
val installedTestFramework = TestFramework .allItems.singleOrNull { it.isInstalled }
@@ -914,15 +919,19 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
914
919
updateParametrizationEnabled()
915
920
}
916
921
ProjectType .Spring -> {
922
+ springProfileNames.text = settings.springProfileNames
917
923
springTestType.item =
918
924
if (isSpringConfigSelected()) settings.springTestType else SpringTestType .defaultItem
925
+ updateMockStrategy(springTestType.item)
919
926
updateSpringSettings()
920
927
updateTestFrameworksList(springTestType.item)
921
928
}
922
929
ProjectType .Python ,
923
930
ProjectType .JavaScript -> { }
924
931
}
925
932
933
+ mockStrategies.isEnabled = ! isSpringConfigSelected()
934
+ updateStaticMockEnabled()
926
935
updateMockStrategyList()
927
936
928
937
itemsToHelpTooltip.forEach { (box, tooltip) ->
@@ -976,7 +985,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
976
985
}
977
986
978
987
private fun configureSpringTestFrameworkIfRequired () {
979
- if (springConfig.item != NO_SPRING_CONFIGURATION_OPTION ) {
988
+ if (isSpringConfigSelected() ) {
980
989
981
990
SpringModule .installedItems
982
991
.forEach { configureSpringTestDependency(it) }
@@ -1192,7 +1201,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
1192
1201
1193
1202
springTestType.item = SpringTestType .defaultItem
1194
1203
1195
- profileNames .text = " "
1204
+ springProfileNames .text = " "
1196
1205
}
1197
1206
1198
1207
if (isSpringConfigSelected() && springTestType.item == UNIT_TEST ) {
@@ -1208,17 +1217,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
1208
1217
val item = comboBox.item as SpringTestType
1209
1218
1210
1219
updateTestFrameworksList(item)
1211
-
1212
- when (item) {
1213
- UNIT_TEST -> {
1214
- mockStrategies.item = MockStrategyApi .springDefaultItem
1215
- staticsMocking.isSelected = true
1216
- }
1217
- INTEGRATION_TEST -> {
1218
- mockStrategies.item = MockStrategyApi .springIntegrationTestItem
1219
- staticsMocking.isSelected = false
1220
- }
1221
- }
1220
+ updateMockStrategy(item)
1222
1221
updateMockStrategyList()
1223
1222
updateControlsEnabledStatus()
1224
1223
}
@@ -1232,6 +1231,21 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
1232
1231
}
1233
1232
}
1234
1233
1234
+ private fun updateMockStrategy (springTestType : SpringTestType ){
1235
+ when (springTestType) {
1236
+ UNIT_TEST -> {
1237
+ if (isSpringConfigSelected()){
1238
+ mockStrategies.item = MockStrategyApi .springDefaultItem
1239
+ staticsMocking.isSelected = true
1240
+ }
1241
+ }
1242
+ INTEGRATION_TEST -> {
1243
+ mockStrategies.item = MockStrategyApi .springIntegrationTestItem
1244
+ staticsMocking.isSelected = false
1245
+ }
1246
+ }
1247
+ }
1248
+
1235
1249
private lateinit var currentFrameworkItem: TestFramework
1236
1250
1237
1251
private fun updateTestFrameworksList (parametrizedTestSource : ParametrizedTestSource ) {
@@ -1321,7 +1335,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
1321
1335
index : Int , selected : Boolean , hasFocus : Boolean
1322
1336
) {
1323
1337
this .append(value.displayName, SimpleTextAttributes .REGULAR_ATTRIBUTES )
1324
- if (springConfig.item != NO_SPRING_CONFIGURATION_OPTION ) {
1338
+ if (isSpringConfigSelected() ) {
1325
1339
SpringModule .installedItems
1326
1340
// only first missing test framework is shown to avoid overflowing ComboBox
1327
1341
.firstOrNull { ! it.testFrameworkInstalled }
@@ -1384,10 +1398,10 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
1384
1398
1385
1399
if (isSpringConfigSelected()) {
1386
1400
mockStrategies.isEnabled = false
1387
- profileNames .isEnabled = true
1401
+ springProfileNames .isEnabled = true
1388
1402
springTestType.isEnabled = ! isXmlSpringConfigUsed()
1389
1403
} else {
1390
- profileNames .isEnabled = false
1404
+ springProfileNames .isEnabled = false
1391
1405
springTestType.isEnabled = false
1392
1406
}
1393
1407
}
0 commit comments