@@ -24,7 +24,6 @@ import org.utbot.framework.codegen.domain.models.ClassModels
24
24
import org.utbot.framework.codegen.domain.models.SpringTestClassModel
25
25
import org.utbot.framework.plugin.api.ClassId
26
26
import org.utbot.framework.plugin.api.UtCompositeModel
27
- import org.utbot.framework.plugin.api.UtModel
28
27
import org.utbot.framework.plugin.api.util.id
29
28
import org.utbot.framework.plugin.api.util.objectClassId
30
29
@@ -45,6 +44,8 @@ class CgSpringTestClassConstructor(context: CgContext): CgAbstractTestClassConst
45
44
fields + = constructClassFields(testClassModel.injectedMockModels, injectMocksClassId)
46
45
fields + = mockedFields
47
46
47
+ clearUnwantedVariableModels()
48
+
48
49
val (closeableField, closeableMethods) = constructMockitoCloseables()
49
50
fields + = closeableField
50
51
methodRegions + = closeableMethods
@@ -117,6 +118,28 @@ class CgSpringTestClassConstructor(context: CgContext): CgAbstractTestClassConst
117
118
return constructedDeclarations
118
119
}
119
120
121
+ /* *
122
+ * Clears the results of variable instantiations that occured
123
+ * when we create class variables with specific annotations.
124
+ * Actually, only mentioned variables should be stored in `valueByModelId`.
125
+ *
126
+ * This is a kind of HACK.
127
+ * It is better to distinguish creating variable by model with all
128
+ * related side effects and just creating a variable definition,
129
+ * but it will take very long time to do it now.
130
+ */
131
+ private fun clearUnwantedVariableModels () {
132
+ val whiteListOfModels =
133
+ listOf (
134
+ variableConstructor.mockedModelsVariables,
135
+ variableConstructor.injectedMocksModelsVariables
136
+ ).flatMap { modelSet -> modelSet.keys.map { models -> context.getIdByModel(models.first()) } }
137
+
138
+ valueByModelId
139
+ .filter { it.key !in whiteListOfModels }
140
+ .forEach { valueByModelId.remove(it.key) }
141
+ }
142
+
120
143
private fun constructMockitoCloseables (): Pair <CgFieldDeclaration , CgMethodsCluster > {
121
144
val mockitoCloseableVarName = " mockitoCloseable"
122
145
val mockitoCloseableVarType = java.lang.AutoCloseable ::class .id
0 commit comments