Skip to content

Commit 069c27d

Browse files
committed
Support JS projects in CodeGenerator also
1 parent 48b3e3b commit 069c27d

File tree

7 files changed

+23
-16
lines changed

7 files changed

+23
-16
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/CodeGenerator.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.utbot.framework.codegen.domain.ForceStaticMocking
55
import org.utbot.framework.codegen.domain.HangingTestsTimeout
66
import org.utbot.framework.codegen.domain.ParametrizedTestSource
77
import org.utbot.framework.codegen.domain.ProjectType
8+
import org.utbot.framework.codegen.domain.ProjectType.*
89
import org.utbot.framework.codegen.domain.RuntimeExceptionTestsBehaviour
910
import org.utbot.framework.codegen.domain.StaticsMocking
1011
import org.utbot.framework.codegen.domain.TestFramework
@@ -30,7 +31,7 @@ import java.time.format.DateTimeFormatter
3031
open class CodeGenerator(
3132
val classUnderTest: ClassId,
3233
//TODO: support setting `projectType` in Sarif plugins, UtBotJava api, etc.
33-
val projectType: ProjectType = ProjectType.PURE_JVM,
34+
val projectType: ProjectType = PureJvm,
3435
paramNames: MutableMap<ExecutableId, List<String>> = mutableMapOf(),
3536
generateUtilClassFile: Boolean = false,
3637
testFramework: TestFramework = TestFramework.defaultItem,
@@ -81,9 +82,10 @@ open class CodeGenerator(
8182
return withCustomContext(testClassCustomName) {
8283
context.withTestClassFileScope {
8384
when (context.projectType) {
84-
ProjectType.PURE_JVM,
85-
ProjectType.PYTHON -> generateForSimpleClass(cgTestSets)
86-
ProjectType.SPRING -> generateForSpringClass(cgTestSets)
85+
PureJvm,
86+
Python,
87+
JavaScript -> generateForSimpleClass(cgTestSets)
88+
Spring -> generateForSpringClass(cgTestSets)
8789
}
8890
}
8991
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,18 +716,22 @@ enum class ProjectType {
716716
/**
717717
* Standard JVM project without DI frameworks
718718
*/
719-
PURE_JVM,
719+
PureJvm,
720720

721721
/**
722722
* Spring or Spring Boot project
723723
*/
724-
SPRING,
724+
Spring,
725725

726726
/**
727727
* Python project
728728
*/
729-
PYTHON,
729+
Python,
730730

731+
/**
732+
* JavaScript project
733+
*/
734+
JavaScript,
731735
}
732736

733737
enum class TypeReplacementApproach {

utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj
172172
model.testFramework = testFrameworks.item
173173
model.timeout = TimeUnit.SECONDS.toMillis(timeoutSpinnerForTotalTimeout.number.toLong())
174174
model.testSourceRootPath = testSourceFolderField.text
175-
model.projectType = ProjectType.PYTHON
175+
model.projectType = ProjectType.Python
176176

177177
val settings = model.project.service<Settings>()
178178
with(settings) {

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import org.utbot.framework.CancellationStrategyType.CANCEL_EVERYTHING
2525
import org.utbot.framework.CancellationStrategyType.NONE
2626
import org.utbot.framework.CancellationStrategyType.SAVE_PROCESSED_RESULTS
2727
import org.utbot.framework.UtSettings
28-
import org.utbot.framework.codegen.domain.ProjectType
28+
import org.utbot.framework.codegen.domain.ProjectType.*
2929
import org.utbot.framework.codegen.domain.TypeReplacementApproach
3030
import org.utbot.framework.plugin.api.ClassId
3131
import org.utbot.framework.plugin.api.ApplicationContext
@@ -177,9 +177,10 @@ object UtTestsDialogProcessor {
177177
val staticMockingConfigured = model.staticsMocking.isConfigured
178178

179179
val applicationContext = when (model.projectType) {
180-
ProjectType.PURE_JVM,
181-
ProjectType.PYTHON -> ApplicationContext(mockFrameworkInstalled, staticMockingConfigured)
182-
ProjectType.SPRING -> {
180+
PureJvm,
181+
Python,
182+
JavaScript -> ApplicationContext(mockFrameworkInstalled, staticMockingConfigured)
183+
Spring -> {
183184
val shouldUseImplementors = when (model.typeReplacementApproach) {
184185
TypeReplacementApproach.DO_NOT_REPLACE -> false
185186
TypeReplacementApproach.REPLACE_IF_POSSIBLE -> true

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
241241
DependencyInjectionFramework.allItems.forEach {
242242
it.isInstalled = findDependencyInjectionLibrary(model.project, model.testModule, it) != null
243243
}
244-
model.projectType = if (SpringBeans.isInstalled) ProjectType.SPRING else ProjectType.PURE_JVM
244+
model.projectType = if (SpringBeans.isInstalled) ProjectType.Spring else ProjectType.PureJvm
245245

246246
StaticsMocking.allItems.forEach {
247247
it.isConfigured = staticsMockingConfigured()
@@ -526,7 +526,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
526526
model.testSourceRoot?.apply { model.updateSourceRootHistory(this.toNioPath().toString()) }
527527

528528
//TODO: obtain this values from UI controls https://github.com/UnitTestBot/UTBotJava/issues/1929
529-
model.projectType = ProjectType.PURE_JVM
529+
model.projectType = ProjectType.PureJvm
530530
model.typeReplacementApproach = TypeReplacementApproach.DO_NOT_REPLACE
531531

532532
val settings = model.project.service<Settings>()

utbot-js/src/main/kotlin/codegen/JsCodeGenerator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class JsCodeGenerator(
3333
) {
3434
private var context: CgContext = CgContext(
3535
classUnderTest = classUnderTest,
36+
projectType = ProjectType.JavaScript,
3637
paramNames = paramNames,
3738
testFramework = testFramework,
3839
mockFramework = MockFramework.MOCKITO,

utbot-python/src/main/kotlin/org/utbot/python/framework/codegen/model/PythonCodeGenerator.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import org.utbot.python.newtyping.pythonAnyType
4343
import org.utbot.python.newtyping.pythonModules
4444
import org.utbot.python.newtyping.pythonTypeRepresentation
4545
import org.utbot.python.framework.codegen.toPythonRawString
46-
import org.utbot.python.newtyping.pythonDescription
4746
import org.utbot.python.newtyping.pythonName
4847

4948
class PythonCodeGenerator(
@@ -61,7 +60,7 @@ class PythonCodeGenerator(
6160
testClassPackageName: String = classUnderTest.packageName
6261
) : CodeGenerator(
6362
classUnderTest = classUnderTest,
64-
projectType = ProjectType.PYTHON,
63+
projectType = ProjectType.Python,
6564
paramNames = paramNames,
6665
generateUtilClassFile = true,
6766
testFramework = testFramework,

0 commit comments

Comments
 (0)