Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fixed error with unavailable mock classes from mock framework
  • Loading branch information
Damtev committed Oct 4, 2022
commit a53d1795f4326ff1c6c0586050c2bcf0f9cdaeab
Original file line number Diff line number Diff line change
Expand Up @@ -1316,21 +1316,20 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
resources.forEach {
// First argument for mocked resource declaration initializer is a target type.
// Pass this argument as a type parameter for the mocked resource

// TODO this type parameter (required for Kotlin test) is unused until the proper implementation
// of generics in code generation https://github.com/UnitTestBot/UTBotJava/issues/88
@Suppress("UNUSED_VARIABLE")
val typeParameter = when (val firstArg = (it.initializer as CgMethodCall).arguments.first()) {
is CgGetJavaClass -> firstArg.classId
is CgVariable -> firstArg.type
else -> error("Unexpected mocked resource declaration argument $firstArg")
}
val varType = CgClassId(
it.variableType,
TypeParameters(listOf(typeParameter)),
isNullable = true,
)

+CgDeclaration(
varType,
it.variableType,
it.variableName,
// guard initializer to reuse typecast creation logic
initializer = guardExpression(varType, nullLiteral()).expression,
initializer = nullLiteral(),
isMutable = true,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
mockClassCounter.variable
)
val mockedConstructionDeclaration = CgDeclaration(
CgClassId(MockitoStaticMocking.mockedConstructionClassId),
MockitoStaticMocking.mockedConstructionClassId,
variableConstructor.constructVarName(MOCKED_CONSTRUCTION_NAME),
mockConstructionInitializer
)
Expand Down Expand Up @@ -295,7 +295,7 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
val classMockStaticCall = mockStatic(modelClass)
val mockedStaticVariableName = variableConstructor.constructVarName(MOCKED_STATIC_NAME)
CgDeclaration(
CgClassId(MockitoStaticMocking.mockedStaticClassId),
MockitoStaticMocking.mockedStaticClassId,
mockedStaticVariableName,
classMockStaticCall
).also {
Expand Down