Skip to content

Commit d2cea77

Browse files
UTBot doesn't show test source from other modules for Gradle project #1060
Better source roots sorting, attempt #2
1 parent 8f7cff8 commit d2cea77

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.intellij.ui.SimpleTextAttributes
1515
import com.intellij.util.ArrayUtil
1616
import com.intellij.util.ui.UIUtil
1717
import java.io.File
18+
import java.util.Comparator
1819
import javax.swing.DefaultComboBoxModel
1920
import javax.swing.JList
2021
import org.jetbrains.kotlin.idea.util.rootManager
@@ -66,14 +67,16 @@ class TestFolderComboWithBrowseButton(private val model: GenerateTestsModel) :
6667
}
6768
}
6869
// The first sorting to obtain the best candidate
69-
val testRoots = model.getAllTestSourceRoots().distinct().sortedWith(
70-
compareByDescending<TestSourceRoot> {
70+
val testRoots = model.getAllTestSourceRoots().distinct().sortedWith(object : Comparator<TestSourceRoot> {
71+
override fun compare(o1: TestSourceRoot, o2: TestSourceRoot): Int {
7172
// Heuristics: Dirs with language == codegenLanguage should go first
72-
it.expectedLanguage == model.codegenLanguage
73-
}.thenBy {
73+
val languageOrder = (o1.expectedLanguage == model.codegenLanguage).compareTo(o2.expectedLanguage == model.codegenLanguage)
74+
if (languageOrder != 0) return -languageOrder
7475
// Heuristics: move root that is 'closer' to module 'common' directory to the first position
75-
StringUtil.commonPrefixLength(commonModuleSourceDirectory, it.dir.toNioPath().toString())
76-
}).toMutableList()
76+
return -StringUtil.commonPrefixLength(commonModuleSourceDirectory, o1.dir.toNioPath().toString())
77+
.compareTo(StringUtil.commonPrefixLength(commonModuleSourceDirectory, o2.dir.toNioPath().toString()))
78+
}
79+
}).toMutableList()
7780

7881
val theBest = if (testRoots.isNotEmpty()) testRoots[0] else null
7982

0 commit comments

Comments
 (0)