diff --git a/java/execution/impl/src/com/intellij/testIntegration/SelectTestStep.kt b/java/execution/impl/src/com/intellij/testIntegration/SelectTestStep.kt index 7600a9da45dc..77c7b9e2931b 100644 --- a/java/execution/impl/src/com/intellij/testIntegration/SelectTestStep.kt +++ b/java/execution/impl/src/com/intellij/testIntegration/SelectTestStep.kt @@ -130,32 +130,9 @@ class SelectTestStep(title: String?, } private fun getConfigurations(entry: RecentTestsPopupEntry): List { - val items = mutableListOf() - - entry.accept(object : TestEntryVisitor() { - override fun visitTest(test: SingleTestEntry) { - val configuration = test.suite?.runConfigurationEntry ?: RunConfigurationEntry(test.runConfiguration) - items.add(test.suite ?: return) - - if (isSingleTestConfiguration(configuration)) { - items.add(test.suite ?: return) - return - } - - items.add(configuration) - if (configuration.suites.size > 1) { - items.add(0, test.suite ?: return) - } - } - - private fun isSingleTestConfiguration(configuration: RunConfigurationEntry): Boolean { - val suites = configuration.suites - return suites.size == 1 && suites[0].tests.size == 1 - } - - }) - - return items + val collector = TestConfigurationCollector() + entry.accept(collector) + return collector.getEnclosingConfigurations() } } diff --git a/java/execution/impl/src/com/intellij/testIntegration/TestEntryVisitors.kt b/java/execution/impl/src/com/intellij/testIntegration/TestEntryVisitors.kt index 87cabc54a774..9bfb74944982 100644 --- a/java/execution/impl/src/com/intellij/testIntegration/TestEntryVisitors.kt +++ b/java/execution/impl/src/com/intellij/testIntegration/TestEntryVisitors.kt @@ -56,4 +56,20 @@ class ConfigurationsCollector : TestEntryVisitor() { override fun visitSuite(suite: SuiteEntry) { entries.add(suite) } +} + + +class TestConfigurationCollector : TestEntryVisitor() { + private val items = mutableListOf() + + fun getEnclosingConfigurations(): List = items + + override fun visitTest(test: SingleTestEntry) { + val configurationEntry = test.suite?.runConfigurationEntry ?: RunConfigurationEntry(test.runConfiguration) + items.add(configurationEntry) + if (test.suite != null && configurationEntry.suites.size > 1) { + items.add(0, test.suite!!) + } + } + } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsTest.kt b/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsTest.kt index 7545e8a933d9..e040860917e4 100644 --- a/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsTest.kt +++ b/java/java-tests/testSrc/com/intellij/testIntergration/RecentTestsTest.kt @@ -20,6 +20,9 @@ import com.intellij.execution.testframework.sm.runner.states.TestStateInfo.Magni import com.intellij.execution.testframework.sm.runner.states.TestStateInfo.Magnitude.PASSED_INDEX import com.intellij.testFramework.LightIdeaTestCase import com.intellij.testIntegration.RecentTestsData +import com.intellij.testIntegration.RunConfigurationEntry +import com.intellij.testIntegration.SuiteEntry +import com.intellij.testIntegration.TestConfigurationCollector import org.assertj.core.api.Assertions.assertThat import org.mockito.Mockito.`when` import org.mockito.Mockito.mock @@ -99,6 +102,41 @@ class RecentTestsStepTest: LightIdeaTestCase() { assertThat(testsToShow).hasSize(1) } + + fun `test additional entries`() { + data.addSuite("Test2".suite(), now, allTests) + data.addSuite("Test".suite(), now, allTests) + data.addTest("Test.sss".test(), FAILED_INDEX, now, allTests) + + val tests = data.getTestsToShow() + assertThat(tests).hasSize(1) + + val failedTest = tests[0] + + val collector = TestConfigurationCollector() + failedTest.accept(collector) + val configs = collector.getEnclosingConfigurations() + + assertThat(configs).hasSize(2) + assertThat(configs[0]).isInstanceOf(SuiteEntry::class.java) + assertThat(configs[1]).isInstanceOf(RunConfigurationEntry::class.java) + } + + fun `test if configuration consists of single test show only configuration`() { + data.addSuite("Test".suite(), now, allTests) + data.addTest("Test.sss".test(), FAILED_INDEX, now, allTests) + val tests = data.getTestsToShow() + + assertThat(tests).hasSize(1) + + val collector = TestConfigurationCollector() + tests[0].accept(collector) + val configs = collector.getEnclosingConfigurations() + + assertThat(configs).hasSize(1) + assertThat(configs[0]).isInstanceOf(RunConfigurationEntry::class.java) + } + } \ No newline at end of file