Skip to content
Merged
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 @@ -48,6 +48,7 @@ import org.utbot.framework.codegen.tree.CgStatementConstructor
import org.utbot.framework.codegen.tree.CgStatementConstructorImpl
import org.utbot.framework.codegen.tree.CgVariableConstructor
import org.utbot.framework.codegen.tree.hasAmbiguousOverloadsOf
import org.utbot.framework.codegen.tree.importIfNeeded
import org.utbot.framework.codegen.util.isAccessibleFrom
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.ConstructorId
Expand Down Expand Up @@ -287,6 +288,10 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
nameGenerator.variableName(MOCKED_CONSTRUCTION_NAME),
mockConstructionInitializer.mockConstructionCall
)

importIfNeeded(MockitoStaticMocking.mockedConstructionClassId)
importIfNeeded(classId)

resources += mockedConstructionDeclaration
+CgAssignment(mockedConstructionDeclaration.variable, mockConstructionInitializer.mockConstructionCall)
mockedStaticConstructions += classId
Expand Down Expand Up @@ -351,6 +356,9 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
).also {
resources += it
+CgAssignment(it.variable, classMockStaticCall)

importIfNeeded(MockitoStaticMocking.mockedStaticClassId)
importIfNeeded(classId)
}
}

Expand All @@ -367,10 +375,6 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
isMock = true
)
)
val contextParameter = variableConstructor.declareParameter(
mockedConstructionContextClassId,
nameGenerator.variableName("context")
)

val mockAnswerStatements = mutableMapOf<Int, List<CgStatement>>()

Expand Down Expand Up @@ -425,12 +429,20 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
listOf(switchCase, CgStatementExecutableCall(mockClassCounter[atomicIntegerGetAndIncrement]()))
}

val contextParameter = variableConstructor.declareParameter(
mockedConstructionContextClassId,
nameGenerator.variableName("context")
)

val answersBlock = CgAnonymousFunction(
voidClassId,
listOf(mockParameter, contextParameter).map { CgParameterDeclaration(it, isVararg = false) },
mockConstructionBody
)

importIfNeeded(mockedConstructionContextClassId)
importIfNeeded(classId)

return MockConstructionBlock(
mockitoClassId[MockitoStaticMocking.mockConstructionMethodId](clazz, answersBlock),
!atMostOneBranchOrAllEmpty
Expand Down