Skip to content

Commit 55d9d43

Browse files
committed
Only mocks accessible from thisInstance require per-class variable
1 parent 6f70c52 commit 55d9d43

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

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

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import org.utbot.framework.plugin.api.UtCompositeModel
1010
import org.utbot.framework.plugin.api.UtDirectSetFieldModel
1111
import org.utbot.framework.plugin.api.UtEnumConstantModel
1212
import org.utbot.framework.plugin.api.UtExecutableCallModel
13-
import org.utbot.framework.plugin.api.UtExecutionSuccess
1413
import org.utbot.framework.plugin.api.UtLambdaModel
1514
import org.utbot.framework.plugin.api.UtModel
1615
import org.utbot.framework.plugin.api.UtNullModel
@@ -37,35 +36,21 @@ class SpringTestClassModelBuilder: TestClassModelBuilder() {
3736
testSets: List<CgMethodTestSet>,
3837
): Pair<Map<ClassId, Set<UtModel>>, Map<ClassId, Set<UtModel>>> {
3938
val thisInstances = mutableSetOf<UtModel>()
40-
val allModelsInExecution = mutableListOf<UtModel>()
39+
val thisInstancesDependentModels = mutableSetOf<UtModel>()
4140

4241
for (testSet in testSets) {
4342
for (execution in testSet.executions) {
44-
execution.stateBefore.thisInstance?.let {
45-
allModelsInExecution += it
46-
thisInstances += it
47-
}
48-
49-
execution.stateAfter.thisInstance?.let {
50-
allModelsInExecution += it
51-
thisInstances += it
52-
}
53-
54-
allModelsInExecution += execution.stateBefore.parameters
55-
allModelsInExecution += execution.stateAfter.parameters
56-
57-
(execution.result as? UtExecutionSuccess)?.model?.let { allModelsInExecution += it }
43+
execution.stateBefore.thisInstance?.let { thisInstances += it }
44+
execution.stateAfter.thisInstance?.let { thisInstances += it }
5845
}
5946
}
6047

61-
val allConstructedModels = mutableSetOf<UtModel>()
62-
allModelsInExecution.forEach { model -> collectRecursively(model, allConstructedModels) }
48+
thisInstances.forEach { model -> collectRecursively(model, thisInstancesDependentModels) }
6349

64-
val mockedModels =
65-
allConstructedModels
66-
.filterTo(mutableSetOf()) { it.isMockModel() && it !in thisInstances }
50+
val dependentMockModels =
51+
thisInstancesDependentModels.filterTo(mutableSetOf()) { it.isMockModel() && it !in thisInstances }
6752

68-
return thisInstances.groupByClassId() to mockedModels.groupByClassId()
53+
return thisInstances.groupByClassId() to dependentMockModels.groupByClassId()
6954
}
7055

7156
private fun Set<UtModel>.groupByClassId(): Map<ClassId, Set<UtModel>> {

0 commit comments

Comments
 (0)