Skip to content

Commit a53d179

Browse files
committed
Fixed error with unavailable mock classes from mock framework
1 parent c9c2a0b commit a53d179

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,21 +1316,20 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
13161316
resources.forEach {
13171317
// First argument for mocked resource declaration initializer is a target type.
13181318
// Pass this argument as a type parameter for the mocked resource
1319+
1320+
// TODO this type parameter (required for Kotlin test) is unused until the proper implementation
1321+
// of generics in code generation https://github.com/UnitTestBot/UTBotJava/issues/88
1322+
@Suppress("UNUSED_VARIABLE")
13191323
val typeParameter = when (val firstArg = (it.initializer as CgMethodCall).arguments.first()) {
13201324
is CgGetJavaClass -> firstArg.classId
13211325
is CgVariable -> firstArg.type
13221326
else -> error("Unexpected mocked resource declaration argument $firstArg")
13231327
}
1324-
val varType = CgClassId(
1325-
it.variableType,
1326-
TypeParameters(listOf(typeParameter)),
1327-
isNullable = true,
1328-
)
1328+
13291329
+CgDeclaration(
1330-
varType,
1330+
it.variableType,
13311331
it.variableName,
1332-
// guard initializer to reuse typecast creation logic
1333-
initializer = guardExpression(varType, nullLiteral()).expression,
1332+
initializer = nullLiteral(),
13341333
isMutable = true,
13351334
)
13361335
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/MockFrameworkManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
237237
mockClassCounter.variable
238238
)
239239
val mockedConstructionDeclaration = CgDeclaration(
240-
CgClassId(MockitoStaticMocking.mockedConstructionClassId),
240+
MockitoStaticMocking.mockedConstructionClassId,
241241
variableConstructor.constructVarName(MOCKED_CONSTRUCTION_NAME),
242242
mockConstructionInitializer
243243
)
@@ -295,7 +295,7 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
295295
val classMockStaticCall = mockStatic(modelClass)
296296
val mockedStaticVariableName = variableConstructor.constructVarName(MOCKED_STATIC_NAME)
297297
CgDeclaration(
298-
CgClassId(MockitoStaticMocking.mockedStaticClassId),
298+
MockitoStaticMocking.mockedStaticClassId,
299299
mockedStaticVariableName,
300300
classMockStaticCall
301301
).also {

0 commit comments

Comments
 (0)