From e8c066027649d86ed08d12292577846513360a4d Mon Sep 17 00:00:00 2001 From: Nikita Vlaev Date: Thu, 14 Jul 2022 00:12:30 +0300 Subject: [PATCH 1/2] Test report reworked (#522) Removed tsv. Sarif and detailed statistics appears only in event log. Bubble with warnings is now of warning type. --- .../org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt index 7204290ee7..12ad2a3302 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt @@ -76,6 +76,7 @@ import com.intellij.util.ui.UIUtil import com.intellij.util.ui.components.BorderLayoutPanel import org.jetbrains.concurrency.Promise import org.jetbrains.concurrency.thenRun +import org.utbot.common.filterWhen import org.utbot.common.PathUtil.toPath import org.utbot.framework.UtSettings import org.utbot.framework.codegen.ForceStaticMocking @@ -126,7 +127,6 @@ import javax.swing.JComponent import javax.swing.JList import javax.swing.JPanel import kotlin.streams.toList -import org.utbot.common.filterWhen private const val RECENTS_KEY = "org.utbot.recents" From 2add318c595dad4093259b0ffcc913d13d4caa6d Mon Sep 17 00:00:00 2001 From: Nikita Vlaev Date: Mon, 18 Jul 2022 11:40:35 +0300 Subject: [PATCH 2/2] Test report for multiple classes (#551) Merge test reports into single one. Refactor conflict triggers (force mocking, test framework conflict...) for GenerateTestsModel. --- .../framework/plugin/api/util/UtContext.kt | 2 +- .../util/mockListeners/ForceMockListener.kt | 10 +- .../mockListeners/ForceStaticMockListener.kt | 10 +- .../engine/util/mockListeners/MockListener.kt | 7 +- .../org/utbot/framework/util/TestUtils.kt | 14 ++ .../generator/CodeGenerationController.kt | 172 +++++++++++------- .../generator/UtTestsDialogProcessor.kt | 20 +- .../plugin/models/GenerateTestsModel.kt | 10 +- .../plugin/ui/GenerateTestsDialogWindow.kt | 10 +- 9 files changed, 159 insertions(+), 96 deletions(-) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/UtContext.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/UtContext.kt index af2e887bb0..0a1f3cce76 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/UtContext.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/UtContext.kt @@ -70,4 +70,4 @@ class UtContext(val classLoader: ClassLoader) : ThreadContextElement } } -inline fun withUtContext(context: UtContext, block: () -> T): T = setUtContext(context).use { block() } \ No newline at end of file +inline fun withUtContext(context: UtContext, block: () -> T): T = setUtContext(context).use { block() } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/ForceMockListener.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/ForceMockListener.kt index d1ae9f2737..0de040d021 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/ForceMockListener.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/ForceMockListener.kt @@ -2,6 +2,8 @@ package org.utbot.engine.util.mockListeners import org.utbot.engine.EngineController import org.utbot.engine.MockStrategy import org.utbot.engine.UtMockInfo +import org.utbot.framework.util.Conflict +import org.utbot.framework.util.ConflictTriggers /** * Listener for mocker events in [org.utbot.engine.UtBotSymbolicEngine]. @@ -9,13 +11,11 @@ import org.utbot.engine.UtMockInfo * * Supposed to be created only if Mockito is not installed. */ -class ForceMockListener: MockListener { - var forceMockHappened = false - private set - +class ForceMockListener(triggers: ConflictTriggers): MockListener(triggers) { override fun onShouldMock(controller: EngineController, strategy: MockStrategy, mockInfo: UtMockInfo) { // If force mocking happened -- сancel engine job controller.job?.cancel(ForceMockCancellationException()) - forceMockHappened = true + + triggers[Conflict.ForceMockHappened] = true } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/ForceStaticMockListener.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/ForceStaticMockListener.kt index 98d5f4c100..d3b4d33b5e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/ForceStaticMockListener.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/ForceStaticMockListener.kt @@ -6,6 +6,8 @@ import org.utbot.engine.UtMockInfo import org.utbot.engine.UtNewInstanceMockInfo import org.utbot.engine.UtStaticMethodMockInfo import org.utbot.engine.UtStaticObjectMockInfo +import org.utbot.framework.util.Conflict +import org.utbot.framework.util.ConflictTriggers /** * Listener for mocker events in [org.utbot.engine.UtBotSymbolicEngine]. @@ -13,17 +15,15 @@ import org.utbot.engine.UtStaticObjectMockInfo * * Supposed to be created only if Mockito inline is not installed. */ -class ForceStaticMockListener: MockListener { - var forceStaticMockHappened = false - private set - +class ForceStaticMockListener(triggers: ConflictTriggers): MockListener(triggers) { override fun onShouldMock(controller: EngineController, strategy: MockStrategy, mockInfo: UtMockInfo) { if (mockInfo is UtNewInstanceMockInfo || mockInfo is UtStaticMethodMockInfo || mockInfo is UtStaticObjectMockInfo) { // If force static mocking happened -- сancel engine job controller.job?.cancel(ForceStaticMockCancellationException()) - forceStaticMockHappened = true + + triggers[Conflict.ForceStaticMockHappened] = true } } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/MockListener.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/MockListener.kt index 50e2d1a6cc..2eb9f23b69 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/MockListener.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/MockListener.kt @@ -3,10 +3,13 @@ package org.utbot.engine.util.mockListeners import org.utbot.engine.EngineController import org.utbot.engine.MockStrategy import org.utbot.engine.UtMockInfo +import org.utbot.framework.util.ConflictTriggers /** * Listener that can be attached using [MockListenerController] to mocker in [org.utbot.engine.UtBotSymbolicEngine]. */ -interface MockListener { - fun onShouldMock(controller: EngineController, strategy: MockStrategy, mockInfo: UtMockInfo) +abstract class MockListener( + val triggers: ConflictTriggers +) { + abstract fun onShouldMock(controller: EngineController, strategy: MockStrategy, mockInfo: UtMockInfo) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/util/TestUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/util/TestUtils.kt index c8778f8cf6..ca96f95c0f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/util/TestUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/util/TestUtils.kt @@ -11,6 +11,7 @@ import java.io.File import java.net.URLClassLoader import java.nio.file.Files import java.nio.file.Paths +import java.util.* import java.util.concurrent.TimeUnit fun List.singleStaticMethod(methodName: String) = @@ -139,4 +140,17 @@ fun compileClassFile(className: String, snippet: Snippet): File { require(javacFinished) { "Javac can't complete in $timeout sec" } return File(workdir.toFile(), "${sourceCodeFile.nameWithoutExtension}.class") +} + +enum class Conflict { + ForceMockHappened, + ForceStaticMockHappened, + TestFrameworkConflict, +} + +class ConflictTriggers( + private val triggers: MutableMap = EnumMap(Conflict::class.java).withDefault { false } +): MutableMap by triggers { + val triggered: Boolean + get() = triggers.values.any { it } } \ No newline at end of file diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt index d37f6b4150..57905e55a8 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/CodeGenerationController.kt @@ -30,7 +30,6 @@ import com.intellij.refactoring.util.classMembers.MemberInfo import com.intellij.testIntegration.TestIntegrationUtils import com.intellij.util.IncorrectOperationException import com.intellij.util.concurrency.AppExecutorUtil -import com.intellij.util.io.exists import com.siyeh.ig.psiutils.ImportUtils import org.jetbrains.kotlin.asJava.classes.KtUltraLightClass import org.jetbrains.kotlin.idea.core.ShortenReferences @@ -54,15 +53,14 @@ import org.utbot.framework.codegen.RegularImport import org.utbot.framework.codegen.StaticImport import org.utbot.framework.codegen.model.CodeGenerator import org.utbot.framework.codegen.model.TestsCodeWithTestReport +import org.utbot.framework.codegen.model.constructor.tree.TestsGenerationReport import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.framework.plugin.api.UtMethod import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.withUtContext -import org.utbot.intellij.plugin.generator.CodeGenerationController.Target.EDT_LATER -import org.utbot.intellij.plugin.generator.CodeGenerationController.Target.READ_ACTION -import org.utbot.intellij.plugin.generator.CodeGenerationController.Target.THREAD_POOL -import org.utbot.intellij.plugin.generator.CodeGenerationController.Target.WRITE_ACTION +import org.utbot.framework.util.Conflict +import org.utbot.intellij.plugin.generator.CodeGenerationController.Target.* import org.utbot.intellij.plugin.models.GenerateTestsModel import org.utbot.intellij.plugin.models.packageName import org.utbot.intellij.plugin.sarif.SarifReportIdea @@ -73,7 +71,6 @@ import org.utbot.intellij.plugin.ui.TestReportUrlOpeningListener import org.utbot.intellij.plugin.ui.TestsReportNotifier import org.utbot.intellij.plugin.ui.WarningTestsReportNotifier import org.utbot.intellij.plugin.ui.utils.getOrCreateSarifReportsPath -import org.utbot.intellij.plugin.ui.utils.getOrCreateTestResourcesPath import org.utbot.intellij.plugin.ui.utils.showErrorDialogLater import org.utbot.intellij.plugin.util.signature import org.utbot.sarif.SarifReport @@ -92,6 +89,7 @@ object CodeGenerationController { val allTestPackages = getPackageDirectories(baseTestDirectory) val latch = CountDownLatch(testSetsByClass.size) + val reports = mutableListOf() for (srcClass in testSetsByClass.keys) { val testSets = testSetsByClass[srcClass] ?: continue try { @@ -102,7 +100,7 @@ object CodeGenerationController { val file = testClass.containingFile runWriteCommandAction(model.project, "Generate tests with UtBot", null, { try { - generateCodeAndSaveReports(testClass, file, testSets, model, latch) + generateCodeAndReport(testClass, file, testSets, model, latch, reports) } catch (e: IncorrectOperationException) { showCreatingClassError(model.project, createTestClassName(srcClass)) } @@ -111,10 +109,27 @@ object CodeGenerationController { showCreatingClassError(model.project, createTestClassName(srcClass)) } } + run(READ_ACTION) { val sarifReportsPath = model.testModule.getOrCreateSarifReportsPath(model.testSourceRoot) run(THREAD_POOL) { - waitForCountDown(latch, model, sarifReportsPath) + waitForCountDown(latch) { + try { + // Parametrized tests are not supported in tests report yet + // TODO JIRA:1507 + if (model.parametrizedTestSource != ParametrizedTestSource.PARAMETRIZE) { + showTestsReport(reports, model) + } + } catch (e: Exception) { + showErrorDialogLater( + model.project, + message = "Cannot save tests generation report: error occurred '${e.message}'", + title = "Failed to save tests report" + ) + } + + mergeSarifReports(model, sarifReportsPath) + } } } } @@ -134,12 +149,12 @@ object CodeGenerationController { } ?: error("No context in thread ${Thread.currentThread()}") } - private fun waitForCountDown(latch: CountDownLatch, model: GenerateTestsModel, sarifReportsPath: Path) { + private fun waitForCountDown(latch: CountDownLatch, action: Runnable) { try { if (!latch.await(5, TimeUnit.SECONDS)) { - run(THREAD_POOL) { waitForCountDown(latch, model, sarifReportsPath) } + run(THREAD_POOL) { waitForCountDown(latch, action) } } else { - mergeSarifReports(model, sarifReportsPath) + action.run() } } catch (ignored: InterruptedException) { } @@ -234,12 +249,13 @@ object CodeGenerationController { return (createFromTemplate.containingFile as PsiClassOwner).classes.first() } - private fun generateCodeAndSaveReports( + private fun generateCodeAndReport( testClass: PsiClass, file: PsiFile, testSets: List, model: GenerateTestsModel, reportsCountDown: CountDownLatch, + reports: MutableList, ) { val selectedMethods = TestIntegrationUtils.extractClassMethods(testClass, false) val testFramework = model.testFramework @@ -297,14 +313,17 @@ object CodeGenerationController { testsCodeWithTestReport.copy(generatedCode = file.text) // creating and saving reports - saveSarifAndTestReports( + reports += testsCodeWithTestReportFormatted.testsGenerationReport + + saveSarifReport( testClassUpdated, testSets, model, testsCodeWithTestReportFormatted, - reportsCountDown ) + reportsCountDown.countDown() + unblockDocument(testClassUpdated.project, editor.document) } } @@ -339,12 +358,11 @@ object CodeGenerationController { private fun MemberInfo.paramNames(): List = (this.member as PsiMethod).parameterList.parameters.map { it.name } - private fun saveSarifAndTestReports( + private fun saveSarifReport( testClass: PsiClass, testSets: List, model: GenerateTestsModel, testsCodeWithTestReport: TestsCodeWithTestReport, - reportsCountDown: CountDownLatch ) { val project = model.project val generatedTestsCode = testsCodeWithTestReport.generatedCode @@ -361,71 +379,103 @@ object CodeGenerationController { message = "Cannot save Sarif report via generated tests: error occurred '${e.message}'", title = "Failed to save Sarif report" ) - } finally { - reportsCountDown.countDown() } + } - try { - // Parametrized tests are not supported in tests report yet - // TODO JIRA:1507 - if (model.parametrizedTestSource != ParametrizedTestSource.PARAMETRIZE) { - executeCommand(testClass.project, "Saving tests report") { - saveTestsReport(testsCodeWithTestReport, model) - } - } - } catch (e: Exception) { - showErrorDialogLater( - project, - message = "Cannot save tests generation report: error occurred '${e.message}'", - title = "Failed to save tests report" - ) + private fun eventLogMessage(): String = + """ + See details in Event Log. + """.trimIndent() + + private fun destinationWarningMessage(testPackageName: String?, classUnderTestPackageName: String): String? { + return if (classUnderTestPackageName != testPackageName) { + """ + Warning: Destination package $testPackageName does not match package of the class $classUnderTestPackageName. + This may cause unnecessary usage of reflection for protected or package-private fields and methods access. + """.trimIndent() + } else { + null } } - private fun saveTestsReport(testsCodeWithTestReport: TestsCodeWithTestReport, model: GenerateTestsModel) { - val testResourcesDirPath = model.testModule.getOrCreateTestResourcesPath(model.testSourceRoot) + private fun showTestsReport(reports: List, model: GenerateTestsModel) { + var hasWarnings = false + require(reports.isNotEmpty()) - require(testResourcesDirPath.exists()) { - "Test resources directory $testResourcesDirPath does not exist" - } + val (notifyMessage, statistics) = if (reports.size == 1) { + val report = reports.first() + processInitialWarnings(report, model) - processInitialWarnings(testsCodeWithTestReport, model) + val message = buildString { + appendHtmlLine(report.toString(isShort = true)) - val notifyMessage = buildString { - appendHtmlLine(testsCodeWithTestReport.testsGenerationReport.toString(isShort = true)) - val classUnderTestPackageName = - testsCodeWithTestReport.testsGenerationReport.classUnderTest.classId.packageFqName.toString() - if (classUnderTestPackageName != model.testPackageName) { - val warningMessage = """ - Warning: Destination package ${model.testPackageName} does not match package of the class $classUnderTestPackageName. - This may cause unnecessary usage of reflection for protected or package-private fields and methods access. - """.trimIndent() - appendHtmlLine(warningMessage) - appendHtmlLine() + val classUnderTestPackageName = + report.classUnderTest.classId.packageFqName.toString() + + destinationWarningMessage(model.testPackageName, classUnderTestPackageName) + ?.let { + appendHtmlLine(it) + appendHtmlLine() + } + + appendHtmlLine(eventLogMessage()) } - val eventLogMessage = """ - See details in Event Log. - """.trimIndent() - appendHtmlLine(eventLogMessage) + hasWarnings = report.hasWarnings + Pair(message, report.detailedStatistics) + } else { + val accumulatedReport = reports.first() + processInitialWarnings(accumulatedReport, model) + + val message = buildString { + appendHtmlLine("${reports.sumBy { it.executables.size }} tests generated for ${reports.size} classes.") + + if (accumulatedReport.initialWarnings.isNotEmpty()) { + accumulatedReport.initialWarnings.forEach { appendHtmlLine(it()) } + appendHtmlLine() + } + + // TODO maybe add statistics info here + + for (report in reports) { + val classUnderTestPackageName = + report.classUnderTest.classId.packageFqName.toString() + + hasWarnings = hasWarnings || report.hasWarnings + if (!model.isMultiPackage) { + val destinationWarning = + destinationWarningMessage(model.testPackageName, classUnderTestPackageName) + if (destinationWarning != null) { + hasWarnings = true + appendHtmlLine(destinationWarning) + appendHtmlLine() + } + } + } + + appendHtmlLine(eventLogMessage()) + } + + Pair(message, null) } - if (testsCodeWithTestReport.testsGenerationReport.hasWarnings) { + if (hasWarnings) { WarningTestsReportNotifier.notify(notifyMessage) } else { TestsReportNotifier.notify(notifyMessage) } - DetailsTestsReportNotifier.notify(testsCodeWithTestReport.testsGenerationReport.detailedStatistics) + statistics?.let { DetailsTestsReportNotifier.notify(it) } } - private fun processInitialWarnings(testsCodeWithTestReport: TestsCodeWithTestReport, model: GenerateTestsModel) { - val hasInitialWarnings = model.forceMockHappened || model.forceStaticMockHappened || model.hasTestFrameworkConflict + private fun processInitialWarnings(report: TestsGenerationReport, model: GenerateTestsModel) { + val hasInitialWarnings = model.conflictTriggers.triggered + if (!hasInitialWarnings) { return } - testsCodeWithTestReport.testsGenerationReport.apply { - if (model.forceMockHappened) { + report.apply { + if (model.conflictTriggers[Conflict.ForceMockHappened] == true) { initialWarnings.add { """ Warning: Some test cases were ignored, because no mocking framework is installed in the project.
@@ -433,7 +483,7 @@ object CodeGenerationController { """.trimIndent() } } - if (model.forceStaticMockHappened) { + if (model.conflictTriggers[Conflict.ForceStaticMockHappened] == true) { initialWarnings.add { """ Warning: Some test cases were ignored, because mockito-inline is not installed in the project.
@@ -441,7 +491,7 @@ object CodeGenerationController { """.trimIndent() } } - if (model.hasTestFrameworkConflict) { + if (model.conflictTriggers[Conflict.TestFrameworkConflict] == true) { initialWarnings.add { """ Warning: There are several test frameworks in the project. diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt index 00227ef822..e8aed74db8 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt @@ -174,20 +174,16 @@ object UtTestsDialogProcessor { withSubstitutionCondition(shouldSubstituteStatics) { val mockFrameworkInstalled = model.mockFramework?.isInstalled ?: true - val forceMockListener = if (!mockFrameworkInstalled) { - ForceMockListener().apply { + if (!mockFrameworkInstalled) { + ForceMockListener(model.conflictTriggers).apply { testCaseGenerator.engineActions.add { engine -> engine.attachMockListener(this) } } - } else { - null } - val forceStaticMockListener = if (!model.staticsMocking.isConfigured) { - ForceStaticMockListener().apply { + if (!model.staticsMocking.isConfigured) { + ForceStaticMockListener(model.conflictTriggers).apply { testCaseGenerator.engineActions.add { engine -> engine.attachMockListener(this) } } - } else { - null } val notEmptyCases = withUtContext(context) { @@ -207,14 +203,6 @@ object UtTestsDialogProcessor { testSetsByClass[srcClass] = notEmptyCases } - forceMockListener?.run { - model.forceMockHappened = forceMockHappened - } - - forceStaticMockListener?.run { - model.forceStaticMockHappened = forceStaticMockHappened - } - timerHandler.cancel(true) } processedClasses++ diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/GenerateTestsModel.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/GenerateTestsModel.kt index a2756ad8d3..befdd61458 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/GenerateTestsModel.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/GenerateTestsModel.kt @@ -17,6 +17,7 @@ import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiClass import com.intellij.refactoring.util.classMembers.MemberInfo import org.jetbrains.kotlin.idea.core.getPackage +import org.utbot.framework.util.ConflictTriggers data class GenerateTestsModel( val project: Project, @@ -27,9 +28,6 @@ data class GenerateTestsModel( var selectedMethods: Set?, var timeout:Long, var generateWarningsForStaticMocking: Boolean = false, - var forceMockHappened: Boolean = false, - var forceStaticMockHappened: Boolean = false, - var hasTestFrameworkConflict: Boolean = false, ) { var testSourceRoot: VirtualFile? = null var testPackageName: String? = null @@ -43,6 +41,12 @@ data class GenerateTestsModel( lateinit var hangingTestsTimeout: HangingTestsTimeout lateinit var forceStaticMocking: ForceStaticMocking lateinit var chosenClassesToMockAlways: Set + + val conflictTriggers: ConflictTriggers = ConflictTriggers() + + val isMultiPackage: Boolean by lazy { + srcClasses.map { it.packageName }.distinct().size != 1 + } } val PsiClass.packageName: String get() = this.containingFile.containingDirectory.getPackage()?.qualifiedName ?: "" \ No newline at end of file diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt index 12ad2a3302..421c9c2cd8 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt @@ -96,6 +96,7 @@ import org.utbot.framework.plugin.api.MockFramework import org.utbot.framework.plugin.api.MockFramework.MOCKITO import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.TreatOverflowAsError +import org.utbot.framework.util.Conflict import org.utbot.intellij.plugin.models.GenerateTestsModel import org.utbot.intellij.plugin.models.jUnit4LibraryDescriptor import org.utbot.intellij.plugin.models.jUnit5LibraryDescriptor @@ -298,8 +299,11 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m } private fun findTestPackageComboValue(): String { - val packageNames = model.srcClasses.map { it.packageName }.distinct() - return if (packageNames.size == 1) packageNames.first() else SAME_PACKAGE_LABEL + return if (model.isMultiPackage) { + model.srcClasses.first().packageName + } else { + SAME_PACKAGE_LABEL + } } /** @@ -621,7 +625,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m configureTestFramework() } - model.hasTestFrameworkConflict = TestFramework.allItems.count { it.isInstalled } > 1 + model.conflictTriggers[Conflict.TestFrameworkConflict] = TestFramework.allItems.count { it.isInstalled } > 1 } private fun configureMockFrameworkIfRequired() {