diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index 4e1ccb2845..b926213df5 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -1341,6 +1341,32 @@ class SpringApplicationContext( ): Boolean = field.fieldId in classUnderTest.allDeclaredFieldIds && field.declaringClass.id !in springInjectedClasses } +enum class SpringTestType( + override val id: String, + override val displayName: String, + override val description: String, + // Integration tests generation requires spring test framework being installed + var frameworkInstalled: Boolean = false, +) : CodeGenerationSettingItem { + UNIT_TESTS( + "Unit tests", + "Unit tests", + "Generate unit tests mocking other classes" + ), + INTEGRATION_TESTS( + "Integration tests", + "Integration tests", + "Generate integration tests autowiring real instance" + ); + + override fun toString() = id + + companion object : CodeGenerationSettingBox { + override val defaultItem = UNIT_TESTS + override val allItems: List = values().toList() + } +} + /** * Describes information about beans obtained from Spring analysis process. * diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/utils/DependencyPatterns.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/utils/DependencyPatterns.kt index f08c46fee3..9effee7219 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/utils/DependencyPatterns.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/utils/DependencyPatterns.kt @@ -76,6 +76,21 @@ fun DependencyInjectionFramework.patterns(): Patterns { return Patterns(moduleLibraryPatterns, libraryPatterns) } +fun DependencyInjectionFramework.testPatterns(): Patterns { + val moduleLibraryPatterns = when (this) { + SpringBoot -> springBootTestModulePatterns + SpringBeans -> springBeansTestModulePatterns + else -> throw UnsupportedOperationException("Unknown dependency injection framework $this") + } + val libraryPatterns = when (this) { + SpringBoot -> springBootTestPatterns + SpringBeans -> springBeansTestPatterns + else -> throw UnsupportedOperationException("Unknown dependency injection framework $this") + } + + return Patterns(moduleLibraryPatterns, libraryPatterns) +} + val JUNIT_4_JAR_PATTERN = Regex("junit-4(\\.1[2-9])(\\.[0-9]+)?") val JUNIT_4_MVN_PATTERN = Regex("junit:junit:4(\\.1[2-9])(\\.[0-9]+)?") val junit4Patterns = listOf(JUNIT_4_JAR_PATTERN, JUNIT_4_MVN_PATTERN) @@ -120,9 +135,24 @@ val springBeansPatterns = listOf(SPRING_BEANS_JAR_PATTERN, SPRING_BEANS_MVN_PATT val SPRING_BEANS_BASIC_MODULE_PATTERN = Regex("spring-beans") val springBeansModulePatterns = listOf(SPRING_BEANS_BASIC_MODULE_PATTERN) +val SPRING_BEANS_TEST_JAR_PATTERN = Regex("spring-test-([0-9]+)(\\.[0-9]+){1,2}") +val SPRING_BEANS_TEST_MVN_PATTERN = Regex("org\\.springframework:spring-test:([0-9]+)(\\.[0-9]+){1,2}") +val springBeansTestPatterns = listOf(SPRING_BEANS_TEST_JAR_PATTERN, SPRING_BEANS_TEST_MVN_PATTERN) + +val SPRING_BEANS_TEST_BASIC_MODULE_PATTERN = Regex("spring-test") +val springBeansTestModulePatterns = listOf(SPRING_BEANS_TEST_BASIC_MODULE_PATTERN) + val SPRING_BOOT_JAR_PATTERN = Regex("spring-boot-([0-9]+)(\\.[0-9]+){1,2}") val SPRING_BOOT_MVN_PATTERN = Regex("org\\.springframework\\.boot:spring-boot:([0-9]+)(\\.[0-9]+){1,2}") val springBootPatterns = listOf(SPRING_BOOT_JAR_PATTERN, SPRING_BOOT_MVN_PATTERN) val SPRING_BOOT_BASIC_MODULE_PATTERN = Regex("spring-boot") val springBootModulePatterns = listOf(SPRING_BOOT_BASIC_MODULE_PATTERN) + +val SPRING_BOOT_TEST_JAR_PATTERN = Regex("spring-boot-test-([0-9]+)(\\.[0-9]+){1,2}") +val SPRING_BOOT_TEST_MVN_PATTERN = Regex("org\\.springframework\\.boot:spring-boot-test:([0-9]+)(\\.[0-9]+){1,2}") + +val springBootTestPatterns = listOf(SPRING_BOOT_TEST_JAR_PATTERN, SPRING_BOOT_TEST_MVN_PATTERN) + +val SPRING_BOOT_TEST_BASIC_MODULE_PATTERN = Regex("spring-boot-test") +val springBootTestModulePatterns = listOf(SPRING_BOOT_TEST_BASIC_MODULE_PATTERN) 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 d8bee1a5d0..50ed3d5392 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 @@ -40,6 +40,8 @@ import kotlin.io.path.exists import kotlin.io.path.pathString import mu.KotlinLogging import org.jetbrains.concurrency.Promise +import org.jetbrains.concurrency.all +import org.jetbrains.concurrency.thenRun import org.jetbrains.idea.maven.project.MavenProjectsManager import org.jetbrains.kotlin.idea.base.util.module import org.utbot.framework.CancellationStrategyType.CANCEL_EVERYTHING @@ -181,8 +183,11 @@ object UtTestsDialogProcessor { .map { it.containingFile.virtualFile } .toTypedArray() - val promise = compile(project, filesToCompile, springConfigClass) - promise.onSuccess { + val compilationPromise = model.preCompilePromises + .all() + .thenAsync { compile(project, filesToCompile, springConfigClass) } + + compilationPromise.onSuccess { if (it.hasErrors() || it.isAborted) return@onSuccess diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/ExternalLibraryDescriptors.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/ExternalLibraryDescriptors.kt index 510d050eba..5863c79b69 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/ExternalLibraryDescriptors.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/ExternalLibraryDescriptors.kt @@ -22,6 +22,13 @@ fun jUnit5ParametrizedTestsLibraryDescriptor(versionInProject: String?) = fun mockitoCoreLibraryDescriptor(versionInProject: String?) = ExternalLibraryDescriptor("org.mockito", "mockito-core", "3.5.0", null, versionInProject ?: "4.2.0") +fun springBootTestLibraryDescriptor(versionInProject: String?) = + ExternalLibraryDescriptor("org.springframework.boot", "spring-boot-test", "2.4.0", null, versionInProject ?: "3.0.6") + +fun springTestLibraryDescriptor(versionInProject: String?) = + ExternalLibraryDescriptor("org.springframework", "spring-test", "2.5", null, versionInProject ?: "6.0.8") + + /** * TestNg requires JDK 11 since version 7.6.0 * For projects with JDK 8 version 7.5 should be installed. 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 34a5708786..85091ccca8 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 @@ -15,11 +15,13 @@ import com.intellij.openapi.project.Project import com.intellij.psi.PsiClass import com.intellij.psi.PsiJavaFile import com.intellij.refactoring.util.classMembers.MemberInfo +import org.jetbrains.concurrency.Promise import org.jetbrains.kotlin.psi.KtFile import org.utbot.framework.SummariesGenerationType import org.utbot.framework.UtSettings import org.utbot.framework.codegen.domain.TypeReplacementApproach import org.utbot.framework.plugin.api.JavaDocCommentStyle +import org.utbot.framework.plugin.api.SpringTestType import org.utbot.framework.util.ConflictTriggers import org.utbot.intellij.plugin.settings.Settings @@ -52,12 +54,14 @@ class GenerateTestsModel( var runInspectionAfterTestGeneration: Boolean = true lateinit var forceStaticMocking: ForceStaticMocking lateinit var chosenClassesToMockAlways: Set + lateinit var springTestType: SpringTestType lateinit var commentStyle: JavaDocCommentStyle lateinit var typeReplacementApproach: TypeReplacementApproach lateinit var profileNames: String val conflictTriggers: ConflictTriggers = ConflictTriggers() + val preCompilePromises: MutableList> = mutableListOf() var runGeneratedTestsWithCoverage : Boolean = false var summariesGenerationType : SummariesGenerationType = UtSettings.summaryGenerationType diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt index a3500c1405..eb82652768 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt @@ -23,6 +23,7 @@ private fun fromGenerateTestsModel(model: GenerateTestsModel): Settings.State { forceStaticMocking = model.forceStaticMocking, parametrizedTestSource = model.parametrizedTestSource, classesToMockAlways = model.chosenClassesToMockAlways.mapTo(mutableSetOf()) { it.name }.toTypedArray(), + springTestType = model.springTestType, fuzzingValue = model.fuzzingValue, runGeneratedTestsWithCoverage = model.runGeneratedTestsWithCoverage, commentStyle = model.commentStyle, 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 820f823034..e667c24650 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 @@ -87,6 +87,7 @@ import org.utbot.framework.codegen.domain.NoStaticMocking import org.utbot.framework.codegen.domain.ParametrizedTestSource import org.utbot.framework.codegen.domain.ProjectType import org.utbot.framework.codegen.domain.SpringBeans +import org.utbot.framework.codegen.domain.SpringBoot import org.utbot.framework.codegen.domain.StaticsMocking import org.utbot.framework.codegen.domain.TestFramework import org.utbot.framework.codegen.domain.TestNg @@ -96,6 +97,8 @@ import org.utbot.framework.plugin.api.CodegenLanguage 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.SpringTestType +import org.utbot.framework.plugin.api.SpringTestType.* import org.utbot.framework.plugin.api.TreatOverflowAsError import org.utbot.framework.plugin.api.utils.MOCKITO_EXTENSIONS_FILE_CONTENT import org.utbot.framework.plugin.api.utils.MOCKITO_EXTENSIONS_FOLDER @@ -108,6 +111,8 @@ import org.utbot.intellij.plugin.models.jUnit5LibraryDescriptor import org.utbot.intellij.plugin.models.jUnit5ParametrizedTestsLibraryDescriptor import org.utbot.intellij.plugin.models.mockitoCoreLibraryDescriptor import org.utbot.intellij.plugin.models.packageName +import org.utbot.intellij.plugin.models.springBootTestLibraryDescriptor +import org.utbot.intellij.plugin.models.springTestLibraryDescriptor import org.utbot.intellij.plugin.models.testNgNewLibraryDescriptor import org.utbot.intellij.plugin.models.testNgOldLibraryDescriptor import org.utbot.intellij.plugin.settings.Settings @@ -119,6 +124,7 @@ import org.utbot.intellij.plugin.ui.utils.addSourceRootIfAbsent import org.utbot.intellij.plugin.ui.utils.allLibraries import org.utbot.intellij.plugin.ui.utils.createTestFrameworksRenderer import org.utbot.intellij.plugin.ui.utils.findDependencyInjectionLibrary +import org.utbot.intellij.plugin.ui.utils.findDependencyInjectionTestLibrary import org.utbot.intellij.plugin.ui.utils.findFrameworkLibrary import org.utbot.intellij.plugin.ui.utils.findParametrizedTestsLibrary import org.utbot.intellij.plugin.ui.utils.getOrCreateTestResourcesPath @@ -197,6 +203,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m private val mockStrategies = createComboBox(MockStrategyApi.values()) private val staticsMocking = JCheckBox("Mock static methods") + private val sprintTestType = createComboBox(SpringTestType.values()) private val springConfig = createComboBoxWithSeparatorsForSpringConfigs(shortenConfigurationNames()) private val profileNames = JBTextField(23).apply { emptyText.text = DEFAULT_SPRING_PROFILE_NAME } @@ -346,21 +353,30 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m setResizable(false) TestFramework.allItems.forEach { - it.isInstalled = findFrameworkLibrary(model.project, model.testModule, it) != null - it.isParametrizedTestsConfigured = findParametrizedTestsLibrary(model.project, model.testModule, it) != null + it.isInstalled = findFrameworkLibrary(model.testModule, it) != null + it.isParametrizedTestsConfigured = findParametrizedTestsLibrary(model.testModule, it) != null } MockFramework.allItems.forEach { - it.isInstalled = findFrameworkLibrary(model.project, model.testModule, it) != null + it.isInstalled = findFrameworkLibrary(model.testModule, it) != null } - DependencyInjectionFramework.allItems.forEach { - it.isInstalled = findDependencyInjectionLibrary(model.project, model.testModule, it) != null - } - model.projectType = if (SpringBeans.isInstalled) ProjectType.Spring else ProjectType.PureJvm - StaticsMocking.allItems.forEach { it.isConfigured = staticsMockingConfigured() } + + DependencyInjectionFramework.allItems.forEach { + it.isInstalled = findDependencyInjectionLibrary(model.srcModule, it) != null + } + val installedDiFramework = when { + SpringBoot.isInstalled -> SpringBoot + SpringBeans.isInstalled -> SpringBeans + else -> null + } + installedDiFramework?.let { + INTEGRATION_TESTS.frameworkInstalled = findDependencyInjectionTestLibrary(model.testModule, it) != null + } + model.projectType = if (installedDiFramework != null) ProjectType.Spring else ProjectType.PureJvm + // Configure notification urls callbacks TestsReportNotifier.urlOpeningListener.callbacks[TestReportUrlOpeningListener.mockitoSuffix]?.plusAssign { configureMockFramework() @@ -395,6 +411,13 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m } if (model.projectType == ProjectType.Spring) { + row("Tests type:") { + cell(sprintTestType) + contextHelp( + "Unit tests do not initialize ApplicationContext
" + + "and do not autowire beans, while integration tests do." + ) + } row("Spring configuration:") { cell(springConfig) contextHelp( @@ -659,6 +682,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m } } model.profileNames = profileNames.text.let { it.ifEmpty { DEFAULT_SPRING_PROFILE_NAME } } + model.springTestType = sprintTestType.item val settings = model.project.service() with(settings) { @@ -806,10 +830,12 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m ?: if (settings.testFramework != Junit4) settings.testFramework else TestFramework.parametrizedDefaultItem } + sprintTestType.item = settings.springTestType + updateTestFrameworksList(settings.parametrizedTestSource) updateParametrizationEnabled() - updateSpringConfigurationEnabled() + updateSpringSettings() updateMockStrategyList() @@ -841,6 +867,8 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m } model.conflictTriggers[Conflict.TestFrameworkConflict] = TestFramework.allItems.count { it.isInstalled } > 1 + + configureSpringTestFrameworkIfRequired() } private fun configureMockFrameworkIfRequired() { @@ -861,11 +889,24 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m } } + private fun configureSpringTestFrameworkIfRequired() { + if (sprintTestType.item == INTEGRATION_TESTS) { + + val framework = when { + SpringBoot.isInstalled -> SpringBoot + SpringBeans.isInstalled -> SpringBeans + else -> error("Both Spring and Spring Boot are not installed") + } + + configureSpringTestDependency(framework) + } + } + private fun configureTestFramework() { val selectedTestFramework = testFrameworks.item val libraryInProject = - findFrameworkLibrary(model.project, model.testModule, selectedTestFramework, LibrarySearchScope.Project) + findFrameworkLibrary(model.testModule, selectedTestFramework, LibrarySearchScope.Project) val versionInProject = libraryInProject?.libraryName?.parseVersion() val sdkVersion = findSdkVersion(model.srcModule).feature @@ -884,11 +925,34 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m .onError { selectedTestFramework.isInstalled = false } } + private fun configureSpringTestDependency(framework: DependencyInjectionFramework) { + val frameworkLibrary = + findDependencyInjectionLibrary(model.srcModule, framework, LibrarySearchScope.Project) + val frameworkTestLibrary = + findDependencyInjectionTestLibrary(model.testModule, framework, LibrarySearchScope.Project) + + val frameworkVersionInProject = frameworkLibrary?.libraryName?.parseVersion() + ?: error("Trying to install Spring test framework, but Spring framework is not found in module ${model.srcModule.name}") + val frameworkTestVersionInProject = frameworkTestLibrary?.libraryName?.parseVersion() + + if (frameworkTestVersionInProject == null || frameworkTestVersionInProject < frameworkVersionInProject) { + val libraryDescriptor = when (framework) { + SpringBoot -> springBootTestLibraryDescriptor(frameworkVersionInProject) + SpringBeans -> springTestLibraryDescriptor(frameworkVersionInProject) + else -> error("Unsupported DI framework type $framework") + } + + model.preCompilePromises += addDependency(model.testModule, libraryDescriptor) + } + + INTEGRATION_TESTS.frameworkInstalled = true + } + private fun configureMockFramework() { val selectedMockFramework = MOCKITO val libraryInProject = - findFrameworkLibrary(model.project, model.testModule, selectedMockFramework, LibrarySearchScope.Project) + findFrameworkLibrary(model.testModule, selectedMockFramework, LibrarySearchScope.Project) val versionInProject = libraryInProject?.libraryName?.parseVersion() selectedMockFramework.isInstalled = true @@ -927,8 +991,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m // TODO: currently first three declarations are copy-pasted from configureTestFramework(), maybe fix this somehow? val selectedTestFramework = testFrameworks.item - val libraryInProject = - findFrameworkLibrary(model.project, model.testModule, selectedTestFramework, LibrarySearchScope.Project) + val libraryInProject = findFrameworkLibrary(model.testModule, selectedTestFramework, LibrarySearchScope.Project) val versionInProject = libraryInProject?.libraryName?.parseVersion() val libraryDescriptor: ExternalLibraryDescriptor? = when (selectedTestFramework) { @@ -951,18 +1014,18 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m * Note that version restrictions will be applied only if they are present on target machine * Otherwise latest release version will be installed. */ - private fun addDependency(module: Module, libraryDescriptor: ExternalLibraryDescriptor): Promise { + private fun addDependency(module: Module, libraryDescriptor: ExternalLibraryDescriptor): Promise { val promise = JavaProjectModelModificationService .getInstance(model.project) //this method returns JetBrains internal Promise that is difficult to deal with, but it is our way .addDependency(model.testModule, libraryDescriptor, DependencyScope.TEST) - promise.thenRun { + + return promise.thenRun { module.allLibraries() .lastOrNull { library -> library.presentableName.contains(libraryDescriptor.id) }?.let { ModuleRootModificationUtil.updateModel(module) { model -> placeEntryToCorrectPlace(model, it) } } } - return promise } /** @@ -1143,9 +1206,27 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m } } - private fun updateSpringConfigurationEnabled() { + private fun updateSpringSettings() { // We check for > 1 because there is already extra-dummy NO_SPRING_CONFIGURATION_OPTION option springConfig.isEnabled = model.projectType == ProjectType.Spring && springConfig.itemCount > 1 + + sprintTestType.renderer = object : ColoredListCellRenderer() { + override fun customizeCellRenderer( + list: JList, value: SpringTestType, + index: Int, selected: Boolean, hasFocus: Boolean + ) { + this.append(value.displayName, SimpleTextAttributes.REGULAR_ATTRIBUTES) + if (value == INTEGRATION_TESTS && !INTEGRATION_TESTS.frameworkInstalled) { + val additionalText = when { + SpringBoot.isInstalled -> " (spring-boot-test will be installed)" + SpringBeans.isInstalled -> " (spring-test will be installed)" + else -> error("Both Spring and Spring Boot are not installed") + } + + this.append(additionalText, SimpleTextAttributes.ERROR_ATTRIBUTES) + } + } + } } private fun staticsMockingConfigured(): Boolean { diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/LibraryMatcher.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/LibraryMatcher.kt index 61bf0b4914..542cb30dd4 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/LibraryMatcher.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/LibraryMatcher.kt @@ -3,53 +3,53 @@ package org.utbot.intellij.plugin.ui.utils import org.utbot.framework.codegen.domain.TestFramework import org.utbot.framework.plugin.api.MockFramework import com.intellij.openapi.module.Module -import com.intellij.openapi.project.Project import com.intellij.openapi.roots.LibraryOrderEntry import org.utbot.framework.codegen.domain.DependencyInjectionFramework import org.utbot.framework.plugin.api.utils.Patterns import org.utbot.framework.plugin.api.utils.parametrizedTestsPatterns import org.utbot.framework.plugin.api.utils.patterns +import org.utbot.framework.plugin.api.utils.testPatterns fun findFrameworkLibrary( - project: Project, - testModule: Module, + module: Module, testFramework: TestFramework, scope: LibrarySearchScope = LibrarySearchScope.Module, -): LibraryOrderEntry? { - return findMatchingLibrary(project, testModule, testFramework.patterns(), scope) -} +): LibraryOrderEntry? = findMatchingLibraryOrNull(module, testFramework.patterns(), scope) fun findFrameworkLibrary( - project: Project, - testModule: Module, + module: Module, mockFramework: MockFramework, scope: LibrarySearchScope = LibrarySearchScope.Module, -): LibraryOrderEntry? = findMatchingLibrary(project, testModule, mockFramework.patterns(), scope) +): LibraryOrderEntry? = findMatchingLibraryOrNull(module, mockFramework.patterns(), scope) fun findParametrizedTestsLibrary( - project: Project, - testModule: Module, + module: Module, testFramework: TestFramework, scope: LibrarySearchScope = LibrarySearchScope.Module, -): LibraryOrderEntry? = findMatchingLibrary(project, testModule, testFramework.parametrizedTestsPatterns(), scope) +): LibraryOrderEntry? = findMatchingLibraryOrNull(module, testFramework.parametrizedTestsPatterns(), scope) fun findDependencyInjectionLibrary( - project: Project, - testModule: Module, - springModule: DependencyInjectionFramework, + module: Module, + springFrameworkType: DependencyInjectionFramework, scope: LibrarySearchScope = LibrarySearchScope.Module -): LibraryOrderEntry? = findMatchingLibrary(project, testModule, springModule.patterns(), scope) +): LibraryOrderEntry? = findMatchingLibraryOrNull(module, springFrameworkType.patterns(), scope) -private fun findMatchingLibrary( - project: Project, - testModule: Module, +fun findDependencyInjectionTestLibrary( + module: Module, + springFrameworkType: DependencyInjectionFramework, + scope: LibrarySearchScope = LibrarySearchScope.Module +): LibraryOrderEntry? = findMatchingLibraryOrNull(module, springFrameworkType.testPatterns(), scope) + +private fun findMatchingLibraryOrNull( + module: Module, patterns: Patterns, scope: LibrarySearchScope, ): LibraryOrderEntry? { val installedLibraries = when (scope) { - LibrarySearchScope.Module -> testModule.allLibraries() - LibrarySearchScope.Project -> project.allLibraries() + LibrarySearchScope.Module -> module.allLibraries() + LibrarySearchScope.Project -> module.project.allLibraries() } + return installedLibraries .matchesFrameworkPatterns(patterns.moduleLibraryPatterns, patterns.libraryPatterns) } diff --git a/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/settings/CommonSettings.kt b/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/settings/CommonSettings.kt index e1a07f68a4..e93162556e 100644 --- a/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/settings/CommonSettings.kt +++ b/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/settings/CommonSettings.kt @@ -36,6 +36,7 @@ import java.util.concurrent.CompletableFuture import kotlin.reflect.KClass import org.utbot.common.isWindows import org.utbot.framework.SummariesGenerationType +import org.utbot.framework.plugin.api.SpringTestType import org.utbot.framework.plugin.api.isSummarizationCompatible @State( @@ -60,6 +61,7 @@ class Settings(val project: Project) : PersistentStateComponent var treatOverflowAsError: TreatOverflowAsError = TreatOverflowAsError.defaultItem, var parametrizedTestSource: ParametrizedTestSource = ParametrizedTestSource.defaultItem, var classesToMockAlways: Array = Mocker.defaultSuperClassesToMockAlwaysNames.toTypedArray(), + var springTestType: SpringTestType = SpringTestType.defaultItem, var fuzzingValue: Double = 0.05, var runGeneratedTestsWithCoverage: Boolean = false, var commentStyle: JavaDocCommentStyle = JavaDocCommentStyle.defaultItem, @@ -87,6 +89,7 @@ class Settings(val project: Project) : PersistentStateComponent if (treatOverflowAsError != other.treatOverflowAsError) return false if (parametrizedTestSource != other.parametrizedTestSource) return false if (!classesToMockAlways.contentEquals(other.classesToMockAlways)) return false + if (springTestType != other.springTestType) return false if (fuzzingValue != other.fuzzingValue) return false if (runGeneratedTestsWithCoverage != other.runGeneratedTestsWithCoverage) return false if (commentStyle != other.commentStyle) return false @@ -109,6 +112,7 @@ class Settings(val project: Project) : PersistentStateComponent result = 31 * result + treatOverflowAsError.hashCode() result = 31 * result + parametrizedTestSource.hashCode() result = 31 * result + classesToMockAlways.contentHashCode() + result = 31 * result + springTestType.hashCode() result = 31 * result + fuzzingValue.hashCode() result = 31 * result + if (runGeneratedTestsWithCoverage) 1 else 0 result = 31 * result + summariesGenerationType.hashCode() @@ -155,6 +159,8 @@ class Settings(val project: Project) : PersistentStateComponent val classesToMockAlways: Set get() = state.classesToMockAlways.toSet() + val springTestType: SpringTestType get() = state.springTestType + val javaDocCommentStyle: JavaDocCommentStyle get() = state.commentStyle var fuzzingValue: Double diff --git a/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/DialogWindowUtils.kt b/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/DialogWindowUtils.kt index 7183b598a4..c462a1a7a6 100644 --- a/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/DialogWindowUtils.kt +++ b/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/DialogWindowUtils.kt @@ -5,7 +5,7 @@ import com.intellij.ui.SimpleTextAttributes import org.utbot.framework.codegen.domain.TestFramework import javax.swing.JList -fun createTestFrameworksRenderer(willBeInstalledLabel: String): ColoredListCellRenderer { +fun createTestFrameworksRenderer(additionalText: String): ColoredListCellRenderer { return object : ColoredListCellRenderer() { override fun customizeCellRenderer( list: JList, value: TestFramework, @@ -13,7 +13,7 @@ fun createTestFrameworksRenderer(willBeInstalledLabel: String): ColoredListCellR ) { this.append(value.displayName, SimpleTextAttributes.REGULAR_ATTRIBUTES) if (!value.isInstalled) { - this.append(willBeInstalledLabel, SimpleTextAttributes.ERROR_ATTRIBUTES) + this.append(additionalText, SimpleTextAttributes.ERROR_ATTRIBUTES) } } }