Skip to content

Commit 61603e2

Browse files
committed
Rename DependencyInjectionFramework to SpringModule and stop implementing CodeGenerationSettingItem as it's not a setting
1 parent 9675f9b commit 61603e2

File tree

4 files changed

+26
-41
lines changed

4 files changed

+26
-41
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/Domain.kt

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -711,44 +711,29 @@ enum class ProjectType {
711711
JavaScript,
712712
}
713713

714-
abstract class DependencyInjectionFramework(
715-
override val id: String,
716-
override val displayName: String,
717-
override val description: String = "Use $displayName as dependency injection framework",
714+
abstract class SpringModule(
718715
val testFrameworkDisplayName: String,
719716
/**
720717
* Generation Spring specific tests requires special spring test framework being installed,
721718
* so we can use `TestContextManager` from `spring-test` to configure test context in
722719
* spring-analyzer and to run integration tests.
723720
*/
724721
var testFrameworkInstalled: Boolean = false
725-
) : CodeGenerationSettingItem {
722+
) {
726723
var isInstalled = false
727724

728-
companion object : CodeGenerationSettingBox {
729-
override val defaultItem: DependencyInjectionFramework get() = SpringBoot
730-
override val allItems: List<DependencyInjectionFramework> get() = listOf(SpringBoot, SpringBeans)
725+
companion object {
726+
val allItems: List<SpringModule> get() = listOf(SpringBoot, SpringBeans)
731727

732728
val installedItems get() = allItems.filter { it.isInstalled }
733-
734-
/**
735-
* Generation Spring specific tests requires special spring test framework being installed,
736-
* so we can use `TestContextManager` from `spring-test` to configure test context in
737-
* spring-analyzer and to run integration tests.
738-
*/
739-
var testFrameworkInstalled: Boolean = false
740729
}
741730
}
742731

743-
object SpringBeans : DependencyInjectionFramework(
744-
id = "spring-beans",
745-
displayName = "Spring Beans",
732+
object SpringBeans : SpringModule(
746733
testFrameworkDisplayName = "spring-test",
747734
)
748735

749-
object SpringBoot : DependencyInjectionFramework(
750-
id = "spring-boot",
751-
displayName = "Spring Boot",
736+
object SpringBoot : SpringModule(
752737
testFrameworkDisplayName = "spring-boot-test",
753738
)
754739

utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/utils/DependencyPatterns.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.utbot.framework.plugin.api.utils
22

3-
import org.utbot.framework.codegen.domain.DependencyInjectionFramework
3+
import org.utbot.framework.codegen.domain.SpringModule
44
import org.utbot.framework.codegen.domain.Junit4
55
import org.utbot.framework.codegen.domain.Junit5
66
import org.utbot.framework.codegen.domain.SpringBeans
@@ -61,7 +61,7 @@ fun MockFramework.patterns(): Patterns {
6161
return Patterns(moduleLibraryPatterns, libraryPatterns)
6262
}
6363

64-
fun DependencyInjectionFramework.patterns(): Patterns {
64+
fun SpringModule.patterns(): Patterns {
6565
val moduleLibraryPatterns = when (this) {
6666
SpringBoot -> springBootModulePatterns
6767
SpringBeans -> springBeansModulePatterns
@@ -76,7 +76,7 @@ fun DependencyInjectionFramework.patterns(): Patterns {
7676
return Patterns(moduleLibraryPatterns, libraryPatterns)
7777
}
7878

79-
fun DependencyInjectionFramework.testPatterns(): Patterns {
79+
fun SpringModule.testPatterns(): Patterns {
8080
val moduleLibraryPatterns = when (this) {
8181
SpringBoot -> springBootTestModulePatterns
8282
SpringBeans -> springBeansTestModulePatterns

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import org.jetbrains.concurrency.Promise
7878
import org.jetbrains.concurrency.thenRun
7979
import org.utbot.common.PathUtil.toPath
8080
import org.utbot.framework.UtSettings
81-
import org.utbot.framework.codegen.domain.DependencyInjectionFramework
81+
import org.utbot.framework.codegen.domain.SpringModule
8282
import org.utbot.framework.codegen.domain.ForceStaticMocking
8383
import org.utbot.framework.codegen.domain.Junit4
8484
import org.utbot.framework.codegen.domain.Junit5
@@ -361,18 +361,18 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
361361
}
362362

363363

364-
DependencyInjectionFramework.allItems.forEach {
364+
SpringModule.allItems.forEach {
365365
it.isInstalled = findDependencyInjectionLibrary(model.srcModule, it) != null
366366
}
367-
DependencyInjectionFramework.installedItems.forEach {
367+
SpringModule.installedItems.forEach {
368368
it.testFrameworkInstalled = findDependencyInjectionTestLibrary(model.testModule, it) != null
369369
}
370370

371371
val isUtBotSpringRuntimePresent = this::class.java.classLoader.getResource("lib/utbot-spring-analyzer-shadow.jar") != null
372372

373373
model.projectType =
374374
// TODO show some warning, when we see Spring project, but don't have `utBotSpringRuntime`
375-
if (isUtBotSpringRuntimePresent && DependencyInjectionFramework.installedItems.isNotEmpty()) ProjectType.Spring
375+
if (isUtBotSpringRuntimePresent && SpringModule.installedItems.isNotEmpty()) ProjectType.Spring
376376
else ProjectType.PureJvm
377377

378378
// Configure notification urls callbacks
@@ -963,7 +963,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
963963
private fun configureSpringTestFrameworkIfRequired() {
964964
if (springConfig.item != NO_SPRING_CONFIGURATION_OPTION) {
965965

966-
DependencyInjectionFramework.installedItems
966+
SpringModule.installedItems
967967
.filter { it.isInstalled }
968968
.forEach { configureSpringTestDependency(it) }
969969
}
@@ -992,11 +992,11 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
992992
.onError { selectedTestFramework.isInstalled = false }
993993
}
994994

995-
private fun configureSpringTestDependency(framework: DependencyInjectionFramework) {
995+
private fun configureSpringTestDependency(springModule: SpringModule) {
996996
val frameworkLibrary =
997-
findDependencyInjectionLibrary(model.srcModule, framework, LibrarySearchScope.Project)
997+
findDependencyInjectionLibrary(model.srcModule, springModule, LibrarySearchScope.Project)
998998
val frameworkTestLibrary =
999-
findDependencyInjectionTestLibrary(model.testModule, framework, LibrarySearchScope.Project)
999+
findDependencyInjectionTestLibrary(model.testModule, springModule, LibrarySearchScope.Project)
10001000

10011001
val frameworkVersionInProject = frameworkLibrary?.libraryName?.parseVersion()
10021002
?: error("Trying to install Spring test framework, but Spring framework is not found in module ${model.srcModule.name}")
@@ -1005,16 +1005,16 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
10051005
if (frameworkTestVersionInProject == null ||
10061006
!frameworkTestVersionInProject.isCompatibleWith(frameworkVersionInProject)
10071007
) {
1008-
val libraryDescriptor = when (framework) {
1008+
val libraryDescriptor = when (springModule) {
10091009
SpringBoot -> springBootTestLibraryDescriptor(frameworkVersionInProject)
10101010
SpringBeans -> springTestLibraryDescriptor(frameworkVersionInProject)
1011-
else -> error("Unsupported DI framework type $framework")
1011+
else -> error("Unsupported DI framework type $springModule")
10121012
}
10131013

10141014
model.preClasspathCollectionPromises += addDependency(model.testModule, libraryDescriptor)
10151015
}
10161016

1017-
framework.testFrameworkInstalled = true
1017+
springModule.testFrameworkInstalled = true
10181018
}
10191019

10201020
private fun configureMockFramework() {
@@ -1308,7 +1308,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
13081308
) {
13091309
this.append(value.displayName, SimpleTextAttributes.REGULAR_ATTRIBUTES)
13101310
if (springConfig.item != NO_SPRING_CONFIGURATION_OPTION) {
1311-
DependencyInjectionFramework.installedItems
1311+
SpringModule.installedItems
13121312
// only first missing test framework is shown to avoid overflowing ComboBox
13131313
.firstOrNull { !it.testFrameworkInstalled }
13141314
?.let { diFramework ->

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/utils/LibraryMatcher.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.utbot.framework.codegen.domain.TestFramework
44
import org.utbot.framework.plugin.api.MockFramework
55
import com.intellij.openapi.module.Module
66
import com.intellij.openapi.roots.LibraryOrderEntry
7-
import org.utbot.framework.codegen.domain.DependencyInjectionFramework
7+
import org.utbot.framework.codegen.domain.SpringModule
88
import org.utbot.framework.plugin.api.utils.Patterns
99
import org.utbot.framework.plugin.api.utils.parametrizedTestsPatterns
1010
import org.utbot.framework.plugin.api.utils.patterns
@@ -30,15 +30,15 @@ fun findParametrizedTestsLibrary(
3030

3131
fun findDependencyInjectionLibrary(
3232
module: Module,
33-
springFrameworkType: DependencyInjectionFramework,
33+
springModule: SpringModule,
3434
scope: LibrarySearchScope = LibrarySearchScope.Module
35-
): LibraryOrderEntry? = findMatchingLibraryOrNull(module, springFrameworkType.patterns(), scope)
35+
): LibraryOrderEntry? = findMatchingLibraryOrNull(module, springModule.patterns(), scope)
3636

3737
fun findDependencyInjectionTestLibrary(
3838
module: Module,
39-
springFrameworkType: DependencyInjectionFramework,
39+
springModule: SpringModule,
4040
scope: LibrarySearchScope = LibrarySearchScope.Module
41-
): LibraryOrderEntry? = findMatchingLibraryOrNull(module, springFrameworkType.testPatterns(), scope)
41+
): LibraryOrderEntry? = findMatchingLibraryOrNull(module, springModule.testPatterns(), scope)
4242

4343
private fun findMatchingLibraryOrNull(
4444
module: Module,

0 commit comments

Comments
 (0)