Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1552,6 +1551,20 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
val executableUnderTestParameters = testSet.executableId.executable.parameters

return mutableListOf<CgParameterDeclaration>().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)
Expand Down Expand Up @@ -1663,6 +1676,10 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte
private fun createExecutionArguments(testSet: CgMethodTestSet, execution: UtExecution): List<CgExpression> {
val arguments = mutableListOf<CgExpression>()

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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down