Skip to content

Commit 1f24d07

Browse files
committed
Handle UTestSetFieldStatement where instance is a mock
1 parent 3844378 commit 1f24d07

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/converter/UTestInstToUtModelConverter.kt

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,32 @@ class UTestInstToUtModelConverter(
108108
is UTestSetFieldStatement -> {
109109
val instanceExpr = uTestInst.instance
110110

111-
val instanceModel = processExpr(instanceExpr)
112-
require(instanceModel is UtAssembleModel)
113-
114-
val fieldType = uTestInst.field.enclosingClass.classId
115-
val fieldName = uTestInst.field.name
116-
val setValueModel = processExpr(uTestInst.value)
117-
118-
val methodCall = UtExecutableCallModel(
119-
instance = null,
120-
executable = utilMethodProvider.setFieldMethodId,
121-
params = listOf(
122-
instanceModel,
123-
UtPrimitiveModel(fieldType.name),
124-
UtPrimitiveModel(fieldName),
125-
setValueModel,
126-
),
127-
)
128-
129-
instanceModel?.let {
130-
(it.modificationsChain as MutableList).add(methodCall)
111+
when (val instanceModel = processExpr(instanceExpr)) {
112+
is UtAssembleModel -> {
113+
val fieldType = uTestInst.field.enclosingClass.classId
114+
val fieldName = uTestInst.field.name
115+
val setValueModel = processExpr(uTestInst.value)
116+
117+
val methodCall = UtExecutableCallModel(
118+
instance = null,
119+
executable = utilMethodProvider.setFieldMethodId,
120+
params = listOf(
121+
instanceModel,
122+
UtPrimitiveModel(fieldType.name),
123+
UtPrimitiveModel(fieldName),
124+
setValueModel,
125+
),
126+
)
127+
128+
(instanceModel.modificationsChain as MutableList).add(methodCall)
129+
}
130+
is UtCompositeModel -> {
131+
instanceModel.fields[uTestInst.field.fieldId] = processExpr(uTestInst.value)
132+
}
133+
else -> logger.warn {
134+
"Field ${uTestInst.field} can't be set for a model of type ${instanceModel::class}, " +
135+
"when generating tests for ${uTest.callMethodExpression.method}"
136+
}
131137
}
132138
}
133139

0 commit comments

Comments
 (0)