@@ -64,6 +64,20 @@ class RunConfigurationHelper {
6464 companion object {
6565 private val logger = KotlinLogging .logger {}
6666
67+ private fun RunConfiguration.isPatternBased () = this is JavaTestConfigurationBase && testType == " pattern"
68+
69+ // In case we do "generate and run" for many files at once,
70+ // desired run configuration has to be one of "pattern" typed test configuration that may run many tests at once.
71+ // Thus, we sort list of all provided configurations to get desired configuration the first.
72+ private val rcComparator = Comparator <ConfigurationFromContext > { o1, o2 ->
73+ val p1 = o1.configuration.isPatternBased()
74+ val p2 = o2.configuration.isPatternBased()
75+ if (p1 xor p2) {
76+ return @Comparator if (p1) - 1 else 1
77+ }
78+ ConfigurationFromContext .COMPARATOR .compare(o1, o2)
79+ }
80+
6781 fun runTestsWithCoverage (
6882 model : GenerateTestsModel ,
6983 testFilesPointers : MutableList <SmartPsiElementPointer <PsiFile >>,
@@ -91,17 +105,9 @@ class RunConfigurationHelper {
91105 )
92106 run (IntelliJApiHelper .Target .THREAD_POOL ) {
93107 val configurations = ApplicationManager .getApplication().runReadAction(Computable {
94- val list = RunConfigurationProducer .getProducers(model.project)
108+ return @Computable RunConfigurationProducer .getProducers(model.project)
95109 .mapNotNull { it.findOrCreateConfigurationFromContext(myConfigurationContext) }
96- .toMutableList().sortedWith(Comparator <ConfigurationFromContext > { o1, o2 ->
97- val p1 = o1.configuration.isPatternBased()
98- val p2 = o2.configuration.isPatternBased()
99- if (p1 xor p2) {
100- return @Comparator if (p1) - 1 else 1
101- }
102- ConfigurationFromContext .COMPARATOR .compare(o1, o2)
103- })
104- return @Computable list
110+ .toMutableList().sortedWith(rcComparator)
105111 })
106112
107113 val settings = if (configurations.isEmpty()) null else configurations[0 ].configurationSettings
@@ -128,7 +134,5 @@ class RunConfigurationHelper {
128134 }
129135 }
130136 }
131-
132- private fun RunConfiguration.isPatternBased () = this is JavaTestConfigurationBase && testType == " pattern"
133137 }
134138}
0 commit comments