From a41917f5ae4ef7f18b178e9be657d0e17e8f731e Mon Sep 17 00:00:00 2001 From: Egor Kulikov Date: Wed, 3 Aug 2022 18:32:09 +0300 Subject: [PATCH 1/2] Replace Class<*> with ClassId in codegen api --- .../kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt | 3 ++- .../src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt | 2 +- .../org/utbot/framework/codegen/model/CodeGenerator.kt | 7 +++---- .../plugin/sarif/GenerateTestsAndSarifReportFacade.kt | 3 ++- .../intellij/plugin/generator/CodeGenerationController.kt | 3 ++- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt index 097d4d0dea..9fac77bb5d 100644 --- a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt +++ b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt @@ -29,6 +29,7 @@ import org.utbot.framework.plugin.api.TreatOverflowAsError import org.utbot.framework.plugin.api.TestCaseGenerator import org.utbot.framework.plugin.api.UtMethod import org.utbot.framework.plugin.api.UtMethodTestSet +import org.utbot.framework.plugin.api.util.id import org.utbot.summary.summarize import java.io.File import java.lang.reflect.Method @@ -205,7 +206,7 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) : forceStaticMocking == ForceStaticMocking.FORCE && staticsMocking is NoStaticMocking return CodeGenerator( testFramework = testFrameworkByName(testFramework), - classUnderTest = classUnderTest.java, + classUnderTest = classUnderTest.id, codegenLanguage = codegenLanguage, staticsMocking = staticsMocking, forceStaticMocking = forceStaticMocking, diff --git a/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt b/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt index 7df4ff771e..d526c587cb 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt @@ -84,7 +84,7 @@ object UtBotJavaApi { return withUtContext(utContext) { val codeGenerator = CodeGenerator( - classUnderTest = classUnderTest, + classUnderTest = classUnderTest.id, testFramework = testFramework, mockFramework = mockFramework, codegenLanguage = codegenLanguage, diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/CodeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/CodeGenerator.kt index 9904dc13bd..ed2063fd65 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/CodeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/CodeGenerator.kt @@ -1,6 +1,5 @@ package org.utbot.framework.codegen.model -import org.utbot.common.packageName import org.utbot.framework.codegen.ForceStaticMocking import org.utbot.framework.codegen.HangingTestsTimeout import org.utbot.framework.codegen.ParametrizedTestSource @@ -13,14 +12,14 @@ import org.utbot.framework.codegen.model.constructor.tree.TestsGenerationReport import org.utbot.framework.codegen.model.tree.CgTestClassFile import org.utbot.framework.codegen.model.visitor.CgAbstractRenderer import org.utbot.framework.plugin.api.CgMethodTestSet +import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.framework.plugin.api.ExecutableId import org.utbot.framework.plugin.api.MockFramework import org.utbot.framework.plugin.api.UtMethodTestSet -import org.utbot.framework.plugin.api.util.id class CodeGenerator( - private val classUnderTest: Class<*>, + private val classUnderTest: ClassId, paramNames: MutableMap> = mutableMapOf(), testFramework: TestFramework = TestFramework.defaultItem, mockFramework: MockFramework? = MockFramework.defaultItem, @@ -35,7 +34,7 @@ class CodeGenerator( testClassPackageName: String = classUnderTest.packageName, ) { private var context: CgContext = CgContext( - classUnderTest = classUnderTest.id, + classUnderTest = classUnderTest, paramNames = paramNames, testFramework = testFramework, mockFramework = mockFramework ?: MockFramework.MOCKITO, diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt index 725af793e8..4c41010460 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/sarif/GenerateTestsAndSarifReportFacade.kt @@ -5,6 +5,7 @@ import org.utbot.framework.codegen.NoStaticMocking import org.utbot.framework.codegen.model.CodeGenerator import org.utbot.framework.plugin.api.TestCaseGenerator import org.utbot.framework.plugin.api.UtMethodTestSet +import org.utbot.framework.plugin.api.util.id import org.utbot.sarif.SarifReport import org.utbot.sarif.SourceFindingStrategy import org.utbot.summary.summarize @@ -70,7 +71,7 @@ class GenerateTestsAndSarifReportFacade( val isForceStaticMocking = sarifProperties.forceStaticMocking == ForceStaticMocking.FORCE return CodeGenerator( - classUnderTest = targetClass.classUnderTest.java, + classUnderTest = targetClass.classUnderTest.id, testFramework = sarifProperties.testFramework, mockFramework = sarifProperties.mockFramework, staticsMocking = sarifProperties.staticsMocking, 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 91e961ca59..bd263a57cf 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 @@ -59,6 +59,7 @@ import org.utbot.framework.plugin.api.ExecutableId import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.executableId +import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.withUtContext import org.utbot.framework.util.Conflict import org.utbot.intellij.plugin.generator.CodeGenerationController.Target.* @@ -265,7 +266,7 @@ object CodeGenerationController { .runReadActionInSmartMode(Computable { findMethodParamNames(classUnderTest, classMethods) }) val codeGenerator = CodeGenerator( - classUnderTest = classUnderTest.java, + classUnderTest = classUnderTest.id, paramNames = paramNames.toMutableMap(), testFramework = model.testFramework, mockFramework = model.mockFramework, From 9c967ddbe18770eef06702b34257fb67fae8e8c7 Mon Sep 17 00:00:00 2001 From: Egor Kulikov Date: Wed, 3 Aug 2022 18:54:19 +0300 Subject: [PATCH 2/2] Fix compilation --- .../org/utbot/framework/codegen/TestCodeGeneratorPipeline.kt | 3 ++- .../src/main/kotlin/org/utbot/contest/Contest.kt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/utbot-framework/src/test/kotlin/org/utbot/framework/codegen/TestCodeGeneratorPipeline.kt b/utbot-framework/src/test/kotlin/org/utbot/framework/codegen/TestCodeGeneratorPipeline.kt index 213da4803d..edff16ce9b 100644 --- a/utbot-framework/src/test/kotlin/org/utbot/framework/codegen/TestCodeGeneratorPipeline.kt +++ b/utbot-framework/src/test/kotlin/org/utbot/framework/codegen/TestCodeGeneratorPipeline.kt @@ -16,6 +16,7 @@ import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.description +import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.withUtContext import kotlin.reflect.KClass @@ -220,7 +221,7 @@ class TestCodeGeneratorPipeline(private val testFrameworkConfiguration: TestFram val codeGenerator = with(testFrameworkConfiguration) { CodeGenerator( - classUnderTest.java, + classUnderTest.id, paramNames = params, testFramework = testFramework, staticsMocking = staticsMocking, diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt index 76cddd1633..27d6cf7f9a 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt @@ -210,7 +210,7 @@ fun runGeneration( val statsForClass = StatsForClass() val codeGenerator = CodeGenerator( - cut.classId.jClass, + cut.classId, testFramework = junitByVersion(junitVersion), staticsMocking = staticsMocking, forceStaticMocking = forceStaticMocking,