@@ -2,6 +2,7 @@ package org.utbot.framework.codegen.domain.models.builders
2
2
3
3
import org.utbot.framework.codegen.domain.UtModelWrapper
4
4
import org.utbot.framework.codegen.domain.context.CgContext
5
+ import org.utbot.framework.codegen.domain.context.CgContextOwner
5
6
import org.utbot.framework.codegen.domain.models.CgMethodTestSet
6
7
import org.utbot.framework.codegen.domain.models.SpringSpecificInformation
7
8
import org.utbot.framework.codegen.domain.models.SpringTestClassModel
@@ -24,7 +25,9 @@ import org.utbot.framework.plugin.api.util.SpringModelUtils.isAutowiredFromConte
24
25
25
26
typealias TypedModelWrappers = Map <ClassId , Set <UtModelWrapper >>
26
27
27
- class SpringTestClassModelBuilder (val context : CgContext ): TestClassModelBuilder() {
28
+ class SpringTestClassModelBuilder (val context : CgContext ):
29
+ TestClassModelBuilder (),
30
+ CgContextOwner by context {
28
31
29
32
override fun createTestClassModel (classUnderTest : ClassId , testSets : List <CgMethodTestSet >): SpringTestClassModel {
30
33
val baseModel = SimpleTestClassModelBuilder (context).createTestClassModel(classUnderTest, testSets)
@@ -43,23 +46,21 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
43
46
val thisInstancesDependentModels = mutableSetOf<UtModelWrapper >()
44
47
val stateBeforeDependentModels = mutableSetOf<UtModelWrapper >()
45
48
46
- with (context) {
47
- for ((testSetIndex, testSet) in testSets.withIndex()) {
48
- withTestSetIdScope(testSetIndex) {
49
- for ((executionIndex, execution) in testSet.executions.withIndex()) {
50
- withExecutionIdScope(executionIndex) {
51
- setOf (execution.stateBefore.thisInstance, execution.stateAfter.thisInstance)
52
- .filterNotNull()
53
- .forEach { model ->
54
- thisInstanceModels + = model.wrap()
55
- thisInstancesDependentModels + = collectByModel(model)
56
-
57
- }
58
-
59
- (execution.stateBefore.parameters + execution.stateBefore.thisInstance)
60
- .filterNotNull()
61
- .forEach { model -> stateBeforeDependentModels + = collectByModel(model) }
62
- }
49
+ for ((testSetIndex, testSet) in testSets.withIndex()) {
50
+ withTestSetIdScope(testSetIndex) {
51
+ for ((executionIndex, execution) in testSet.executions.withIndex()) {
52
+ withExecutionIdScope(executionIndex) {
53
+ setOf (execution.stateBefore.thisInstance, execution.stateAfter.thisInstance)
54
+ .filterNotNull()
55
+ .forEach { model ->
56
+ thisInstanceModels + = model.wrap()
57
+ thisInstancesDependentModels + = collectByModel(model)
58
+
59
+ }
60
+
61
+ (execution.stateBefore.parameters + execution.stateBefore.thisInstance)
62
+ .filterNotNull()
63
+ .forEach { model -> stateBeforeDependentModels + = collectByModel(model) }
63
64
}
64
65
}
65
66
}
@@ -84,9 +85,7 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
84
85
private fun collectByModel (model : UtModel ): Set <UtModelWrapper > {
85
86
val dependentModels = mutableSetOf<UtModelWrapper >()
86
87
87
- with (context){
88
- collectRecursively(model.wrap(), dependentModels)
89
- }
88
+ collectRecursively(model.wrap(), dependentModels)
90
89
91
90
return dependentModels
92
91
}
@@ -106,51 +105,49 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
106
105
return
107
106
}
108
107
109
- with (context) {
110
- when (val currentModel = currentModelWrapper.model) {
111
- is UtNullModel ,
112
- is UtPrimitiveModel ,
113
- is UtClassRefModel ,
114
- is UtVoidModel ,
115
- is UtEnumConstantModel -> {}
116
- is UtCustomModel -> currentModel.origin?.let {
117
- collectRecursively(it.wrap(currentModelWrapper.modelTagName), allModels)
118
- }
119
- is UtLambdaModel -> {
120
- currentModel.capturedValues.forEach { collectRecursively(it.wrap(), allModels) }
121
- }
122
- is UtArrayModel -> {
123
- currentModel.stores.values.forEach { collectRecursively(it.wrap(), allModels) }
124
- if (currentModel.stores.count() < currentModel.length) {
125
- collectRecursively(currentModel.constModel.wrap(), allModels)
126
- }
108
+ when (val currentModel = currentModelWrapper.model) {
109
+ is UtNullModel ,
110
+ is UtPrimitiveModel ,
111
+ is UtClassRefModel ,
112
+ is UtVoidModel ,
113
+ is UtEnumConstantModel -> {}
114
+ is UtCustomModel -> currentModel.origin?.let {
115
+ collectRecursively(it.wrap(currentModelWrapper.modelTagName), allModels)
116
+ }
117
+ is UtLambdaModel -> {
118
+ currentModel.capturedValues.forEach { collectRecursively(it.wrap(), allModels) }
119
+ }
120
+ is UtArrayModel -> {
121
+ currentModel.stores.values.forEach { collectRecursively(it.wrap(), allModels) }
122
+ if (currentModel.stores.count() < currentModel.length) {
123
+ collectRecursively(currentModel.constModel.wrap(), allModels)
127
124
}
128
- is UtCompositeModel -> {
129
- // Here we traverse fields only.
130
- // Traversing mocks as well will result in wrong models playing
131
- // a role of class fields with @Mock annotation.
132
- currentModel. fields.forEach { (fieldId, model) ->
133
- // We use `modelTagName` in order to distinguish mock models
134
- val modeTagName = if (model.isMockModel()) fieldId.name else null
135
- collectRecursively (model.wrap(modeTagName), allModels)
136
- }
125
+ }
126
+ is UtCompositeModel -> {
127
+ // Here we traverse fields only.
128
+ // Traversing mocks as well will result in wrong models playing
129
+ // a role of class fields with @Mock annotation.
130
+ currentModel.fields.forEach { (fieldId, model) ->
131
+ // We use `modelTagName` in order to distinguish mock models
132
+ val modeTagName = if (model.isMockModel()) fieldId.name else null
133
+ collectRecursively(model.wrap(modeTagName), allModels)
137
134
}
138
- is UtAssembleModel -> {
139
- currentModel.origin?. let { collectRecursively(it.wrap(), allModels) }
140
-
141
- currentModel.instantiationCall.instance?. let { collectRecursively(it.wrap(), allModels) }
142
- currentModel.instantiationCall.params.forEach { collectRecursively(it.wrap(), allModels) }
143
-
144
- currentModel.modificationsChain.forEach { stmt ->
145
- stmt.instance?. let { collectRecursively(it.wrap(), allModels) }
146
- when (stmt) {
147
- is UtStatementCallModel -> stmt.params.forEach { collectRecursively(it.wrap(), allModels) }
148
- is UtDirectSetFieldModel -> collectRecursively( stmt.fieldModel. wrap(), allModels)
149
- }
135
+ }
136
+ is UtAssembleModel -> {
137
+ currentModel.origin?. let { collectRecursively(it.wrap(), allModels) }
138
+
139
+ currentModel.instantiationCall.instance?. let { collectRecursively(it.wrap(), allModels) }
140
+ currentModel.instantiationCall.params.forEach { collectRecursively(it.wrap(), allModels) }
141
+
142
+ currentModel.modificationsChain.forEach { stmt ->
143
+ stmt.instance?. let { collectRecursively(it.wrap(), allModels) }
144
+ when (stmt) {
145
+ is UtStatementCallModel -> stmt.params.forEach { collectRecursively(it. wrap(), allModels) }
146
+ is UtDirectSetFieldModel -> collectRecursively(stmt.fieldModel.wrap(), allModels)
150
147
}
151
148
}
152
- // Python, JavaScript, Go models are not required in Spring
153
149
}
150
+ // Python, JavaScript, Go models are not required in Spring
154
151
}
155
152
}
156
153
}
0 commit comments