@@ -99,9 +99,11 @@ import org.utbot.framework.plugin.api.CodegenLanguage
9999import org.utbot.framework.plugin.api.CodeGenerationSettingItem
100100import org.utbot.framework.plugin.api.SpringConfiguration
101101import org.utbot.framework.plugin.api.SpringTestType.*
102+ import org.utbot.framework.plugin.api.SpringProfileNames
102103import org.utbot.framework.plugin.api.utils.MOCKITO_EXTENSIONS_FILE_CONTENT
103104import org.utbot.framework.plugin.api.utils.MOCKITO_EXTENSIONS_FOLDER
104105import org.utbot.framework.plugin.api.utils.MOCKITO_MOCKMAKER_FILE_NAME
106+ import org.utbot.framework.plugin.api.NO_SPRING_CONFIGURATION_OPTION
105107import org.utbot.framework.util.Conflict
106108import org.utbot.intellij.plugin.models.GenerateTestsModel
107109import org.utbot.intellij.plugin.models.id
@@ -165,9 +167,6 @@ private const val SAME_PACKAGE_LABEL = "same as for sources"
165167
166168private const val WILL_BE_INSTALLED_LABEL = " (will be installed)"
167169
168- private const val NO_SPRING_CONFIGURATION_OPTION = " No configuration"
169- private const val DEFAULT_SPRING_PROFILE_NAME = " default"
170-
171170private const val ACTION_GENERATE = " Generate Tests"
172171private const val ACTION_GENERATE_AND_RUN = " Generate and Run"
173172
@@ -202,7 +201,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
202201
203202 private val springTestType = createComboBox(SpringTestType .values()).also { it.setMinimumAndPreferredWidth(300 ) }
204203 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 }
206205
207206 private val timeoutSpinner =
208207 JBIntSpinner (TimeUnit .MILLISECONDS .toSeconds(model.timeout).toInt(), 1 , Int .MAX_VALUE , 1 ).also {
@@ -245,6 +244,11 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
245244 )
246245 }
247246
247+ private fun shortenConfigurationNameByFullname (fullname : String ): String? {
248+ val allShortenConfigurationNames = shortenConfigurationNames().flatMap { it.second }
249+ return allShortenConfigurationNames.firstOrNull { fullname.endsWith(it) }
250+ }
251+
248252 private fun <T : CodeGenerationSettingItem > createComboBox (values : Array <T >) : ComboBox <T > {
249253 val comboBox = object : ComboBox <T >(DefaultComboBoxModel (values)) {
250254 var maxWidth = 0
@@ -428,7 +432,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
428432 ComboBoxPredicate (springConfig) { isSpringConfigSelected() && ! isXmlSpringConfigUsed() }
429433 )
430434 row(" Active profile(s):" ) {
431- cell(profileNames )
435+ cell(springProfileNames )
432436 contextHelp(
433437 " One or several comma-separated names.<br>" +
434438 " If all names are incorrect, default profile is used"
@@ -736,12 +740,14 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
736740
737741 PresentSpringSettings (
738742 configuration = config,
739- profiles = parseProfileExpression(profileNames .text, DEFAULT_SPRING_PROFILE_NAME ).toList()
743+ profiles = parseProfileExpression(springProfileNames .text, SpringProfileNames .defaultItem ).toList()
740744 )
741745 }
742746 }
743747
744748 model.springTestType = springTestType.item
749+ model.springConfig = springConfig.item.toString()
750+ model.springProfileNames = springProfileNames.text
745751
746752 val settings = model.project.service<Settings >()
747753 with (settings) {
@@ -883,21 +889,20 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
883889 if (settings.fuzzingValue == 0.0 ) 0.0
884890 else settings.fuzzingValue.coerceAtLeast(0.3 )
885891 }
892+ springConfig.item = settings.springConfig
886893 }
887894 else -> {}
888895 }
889896
890897 mockStrategies.item = when (model.projectType) {
891- ProjectType .Spring -> MockStrategyApi .springDefaultItem
898+ ProjectType .Spring ->
899+ if (isSpringConfigSelected()) MockStrategyApi .springDefaultItem else settings.mockStrategy
892900 else -> settings.mockStrategy
893901 }
894902 staticsMocking.isSelected = settings.staticsMocking == MockitoStaticMocking
895903 parametrizedTestSources.isSelected = (settings.parametrizedTestSource == ParametrizedTestSource .PARAMETRIZE
896904 && model.projectType == ProjectType .PureJvm )
897905
898- mockStrategies.isEnabled = true
899- staticsMocking.isEnabled = mockStrategies.item != MockStrategyApi .NO_MOCKS
900-
901906 codegenLanguages.item = model.codegenLanguage
902907
903908 val installedTestFramework = TestFramework .allItems.singleOrNull { it.isInstalled }
@@ -914,15 +919,19 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
914919 updateParametrizationEnabled()
915920 }
916921 ProjectType .Spring -> {
922+ springProfileNames.text = settings.springProfileNames
917923 springTestType.item =
918924 if (isSpringConfigSelected()) settings.springTestType else SpringTestType .defaultItem
925+ updateMockStrategy(springTestType.item)
919926 updateSpringSettings()
920927 updateTestFrameworksList(springTestType.item)
921928 }
922929 ProjectType .Python ,
923930 ProjectType .JavaScript -> { }
924931 }
925932
933+ mockStrategies.isEnabled = ! isSpringConfigSelected()
934+ updateStaticMockEnabled()
926935 updateMockStrategyList()
927936
928937 itemsToHelpTooltip.forEach { (box, tooltip) ->
@@ -976,7 +985,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
976985 }
977986
978987 private fun configureSpringTestFrameworkIfRequired () {
979- if (springConfig.item != NO_SPRING_CONFIGURATION_OPTION ) {
988+ if (isSpringConfigSelected() ) {
980989
981990 SpringModule .installedItems
982991 .forEach { configureSpringTestDependency(it) }
@@ -1192,7 +1201,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
11921201
11931202 springTestType.item = SpringTestType .defaultItem
11941203
1195- profileNames .text = " "
1204+ springProfileNames .text = " "
11961205 }
11971206
11981207 if (isSpringConfigSelected() && springTestType.item == UNIT_TEST ) {
@@ -1208,17 +1217,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
12081217 val item = comboBox.item as SpringTestType
12091218
12101219 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)
12221221 updateMockStrategyList()
12231222 updateControlsEnabledStatus()
12241223 }
@@ -1232,6 +1231,21 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
12321231 }
12331232 }
12341233
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+
12351249 private lateinit var currentFrameworkItem: TestFramework
12361250
12371251 private fun updateTestFrameworksList (parametrizedTestSource : ParametrizedTestSource ) {
@@ -1321,7 +1335,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
13211335 index : Int , selected : Boolean , hasFocus : Boolean
13221336 ) {
13231337 this .append(value.displayName, SimpleTextAttributes .REGULAR_ATTRIBUTES )
1324- if (springConfig.item != NO_SPRING_CONFIGURATION_OPTION ) {
1338+ if (isSpringConfigSelected() ) {
13251339 SpringModule .installedItems
13261340 // only first missing test framework is shown to avoid overflowing ComboBox
13271341 .firstOrNull { ! it.testFrameworkInstalled }
@@ -1384,10 +1398,10 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
13841398
13851399 if (isSpringConfigSelected()) {
13861400 mockStrategies.isEnabled = false
1387- profileNames .isEnabled = true
1401+ springProfileNames .isEnabled = true
13881402 springTestType.isEnabled = ! isXmlSpringConfigUsed()
13891403 } else {
1390- profileNames .isEnabled = false
1404+ springProfileNames .isEnabled = false
13911405 springTestType.isEnabled = false
13921406 }
13931407 }
0 commit comments