diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt index 5723e045dd..33d51fcd0e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/collections/CustomerExamplesTest.kt @@ -16,7 +16,7 @@ internal class CustomerExamplesTest: UtValueTestCaseChecker( testClass = CustomerExamples::class, testCodeGeneration = true, pipelines = listOf( - TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution, parameterizedModeLastStage = Compilation), + TestLastStage(CodegenLanguage.JAVA, lastStage = TestExecution), TestLastStage(CodegenLanguage.KOTLIN, lastStage = CodeGeneration) ) ) { diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt index 7cda4f638a..79662edf90 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/examples/mixed/PrivateConstructorExampleTest.kt @@ -7,18 +7,11 @@ import org.utbot.framework.plugin.api.CodegenLanguage import org.utbot.testcheckers.eq import org.utbot.tests.infrastructure.Compilation -// TODO parameterized tests disabled due to https://github.com/UnitTestBot/UTBotJava/issues/1266 internal class PrivateConstructorExampleTest : UtValueTestCaseChecker( testClass = PrivateConstructorExample::class, pipelines = listOf( - TestLastStage( - CodegenLanguage.JAVA, - parameterizedModeLastStage = Compilation - ), - TestLastStage( - CodegenLanguage.KOTLIN, - parameterizedModeLastStage = Compilation - ) + TestLastStage(CodegenLanguage.JAVA), + TestLastStage(CodegenLanguage.KOTLIN) ) ) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt index 10e83236ca..d20af2483e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt @@ -1487,9 +1487,8 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte substituteStaticFields(statics, isParametrized = true) // build this instance - thisInstance = - genericExecution.stateBefore.thisInstance?.let { - variableConstructor.getOrCreateVariable(it) + thisInstance = genericExecution.stateBefore.thisInstance?.let { + currentMethodParameters[CgParameterKind.ThisInstance] } // build arguments for method under test and parameterized test @@ -1552,6 +1551,20 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte val executableUnderTestParameters = testSet.executableId.executable.parameters return mutableListOf().apply { + // this instance + genericExecution.stateBefore.thisInstance?.let { + val type = wrapTypeIfRequired(it.classId) + val thisInstance = CgParameterDeclaration( + parameter = declareParameter( + type = type, + name = nameGenerator.variableName(type) + ), + isReferenceType = true + ) + this += thisInstance + currentMethodParameters[CgParameterKind.ThisInstance] = thisInstance.parameter + } + // arguments for (index in genericExecution.stateBefore.parameters.indices) { val argumentName = paramNames[executableUnderTest]?.get(index) @@ -1663,6 +1676,10 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte private fun createExecutionArguments(testSet: CgMethodTestSet, execution: UtExecution): List { val arguments = mutableListOf() + execution.stateBefore.thisInstance?.let { + arguments += variableConstructor.getOrCreateVariable(it) + } + for ((paramIndex, paramModel) in execution.stateBefore.parameters.withIndex()) { val argumentName = paramNames[testSet.executableId]?.get(paramIndex) arguments += variableConstructor.getOrCreateVariable(paramModel, argumentName) @@ -1673,7 +1690,6 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte arguments += variableConstructor.getOrCreateVariable(model, field.name) } - val method = currentExecutable!! val needsReturnValue = method.returnType != voidClassId val containsFailureExecution = containsFailureExecution(testSet) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt index 05c5c494a4..b52cd625b7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt @@ -728,6 +728,7 @@ data class CgParameterDeclaration( * - exception expected from MUT with the given arguments */ sealed class CgParameterKind { + object ThisInstance : CgParameterKind() data class Argument(val index: Int) : CgParameterKind() data class Statics(val model: UtModel) : CgParameterKind() object ExpectedResult : CgParameterKind()