Skip to content

Commit 978c5d0

Browse files
committed
Collect missed models in stateAfter
1 parent 4236987 commit 978c5d0

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/models/builders/SpringTestClassModelBuilder.kt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,13 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
4444
for ((index, execution) in testSet.executions.withIndex()) {
4545
execution.stateBefore.thisInstance?.let { model ->
4646
thisInstances += model
47-
context.modelIds += model to model.modelId(index)
48-
49-
val dependentModels = mutableSetOf<UtModel>()
50-
collectRecursively(model, dependentModels)
51-
52-
dependentModels.forEach { model ->
53-
context.modelIds += model to model.modelId(index)
54-
}
55-
thisInstancesDependentModels += dependentModels
47+
thisInstancesDependentModels += collectByThisInstanceModel(model, index)
5648
}
5749

58-
execution.stateAfter.thisInstance?.let { thisInstances += it }
50+
execution.stateAfter.thisInstance?.let { model ->
51+
thisInstances += model
52+
thisInstancesDependentModels += collectByThisInstanceModel(model, index)
53+
}
5954
}
6055
}
6156

@@ -65,6 +60,19 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
6560
return thisInstances.groupByClassId() to dependentMockModels.groupByClassId()
6661
}
6762

63+
private fun collectByThisInstanceModel(model: UtModel, executionIndex: Int): Set<UtModel> {
64+
context.modelIds += model to model.modelId(executionIndex)
65+
66+
val dependentModels = mutableSetOf<UtModel>()
67+
collectRecursively(model, dependentModels)
68+
69+
dependentModels.forEach { model ->
70+
context.modelIds += model to model.modelId(executionIndex)
71+
}
72+
73+
return dependentModels
74+
}
75+
6876
private fun Set<UtModel>.groupByClassId(): Map<ClassId, Set<UtModel>> {
6977
return this.groupBy { it.classId }.mapValues { it.value.toSet() }
7078
}

0 commit comments

Comments
 (0)