Skip to content

Commit 70c67dd

Browse files
tepa46EgorkaKulikov
authored andcommitted
Some fixes in SpringConfigurationHelper
1 parent e0154ad commit 70c67dd

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
192192
private val codegenLanguages = createComboBox(CodegenLanguage.values())
193193
private val testFrameworks = createComboBox(TestFramework.allItems.toTypedArray())
194194

195+
private val javaConfigurationHelper = SpringConfigurationsHelper(".")
196+
private val xmlConfigurationHelper = SpringConfigurationsHelper(File.separator)
197+
195198
private val springConfig = createComboBoxWithSeparatorsForSpringConfigs(shortenConfigurationNames())
196199

197200
private val mockStrategies = createComboBox(MockStrategyApi.values())
@@ -218,10 +221,6 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
218221
parametrizedTestSources to null
219222
)
220223

221-
222-
private val javaConfigurationHelper = SpringConfigurationsHelper(".")
223-
private val xmlConfigurationHelper = SpringConfigurationsHelper(File.separator)
224-
225224
private fun shortenConfigurationNames(): Set<Pair<String?, Collection<String>>> {
226225
val shortenedSortedSpringConfigurationClasses =
227226
javaConfigurationHelper.shortenSpringConfigNames(model.getSortedSpringConfigurationClasses())

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/util/SpringConfigurationsHelper.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ class SpringConfigurationsHelper(val separator: String) {
4646
fullNames.forEach { nameToInfo[it] = NameInfo(it) }
4747
var nameInfoCollection = nameToInfo.values
4848

49-
while (nameInfoCollection.size != nameInfoCollection.distinct().size) {
49+
// this cycle continues until all shortenedNames become unique
50+
while (nameInfoCollection.size != nameInfoCollection.distinctBy { it.shortenedName }.size) {
5051
nameInfoCollection = nameInfoCollection.sortedBy { it.shortenedName }.toMutableList()
5152

52-
for (index in nameInfoCollection.indices) {
53+
var index = 0
54+
while(index < nameInfoCollection.size){
5355
val curShortenedPath = nameInfoCollection[index].shortenedName
5456

5557
// here we search a block of shortened paths that are equivalent
@@ -64,8 +66,9 @@ class SpringConfigurationsHelper(val separator: String) {
6466
}
6567
}
6668

67-
//if the size of this block is one, we should not enlarge it
69+
// if the size of this block is one, we should not enlarge it
6870
if (index == maxIndexWithSamePath - 1) {
71+
index++
6972
continue
7073
}
7174

@@ -75,6 +78,9 @@ class SpringConfigurationsHelper(val separator: String) {
7578
return collectShortenedNames()
7679
}
7780
}
81+
82+
// after enlarging the block, we proceed to search for the next block
83+
index = maxIndexWithSamePath
7884
}
7985
}
8086

0 commit comments

Comments
 (0)